31
Sandia is a multiprogram laborat ory operated by Sandia Corporation, a Lockheed Martin Company, for the United States Department of Energy under contract DE-AC04-94AL85000. Reconnect ‘04 Using PICO Cynthia Phillips , Sandia National Labs

Use Pico

Embed Size (px)

Citation preview

Page 1: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 1/31

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company,for the United States Department of Energy under contract DE-AC04-94AL85000.

Reconnect ‘04 

Using PICO

Cynthia Phillips, Sandia National Labs

Page 2: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 2/31

Slide 2

AMPL Model for 1| prec |

• Declare/compute parameters, sets

 param n > 0 integer; # Number of job

set Jobs := 0..n-1;

 param p {Jobs} >= 0 integer; # Job Duration p(j) param w {Jobs} >= 0 integer; # Job weight (for objective) w(j)

# (predecessor, successor) pairs

set Precedence within Jobs cross Jobs;

# The makespan of the schedule (and latest finish time) param T := sum{j in Jobs} p[j];

w jC  j

Page 3: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 3/31

Slide 3

AMPL Model for 1| prec |

• Declare variables

var x {j in Jobs, t in p[j]..T} binary; 

w jC  j

Page 4: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 4/31

Slide 4

AMPL Model for 1| prec |

minimize WCT:

sum{j in Jobs, t in p[j]..T} w[j] * t * x[j,t];

• subject to TaskDone {j in Jobs}:

sum{t in p[j]..T} x[j,t] = 1;• subject to UnitWork {tu in 1..T}:

sum{j in Jobs, t in tu..tu+p[j]-1 inter p[j]..T} x[j,t] <= 1;

• subject to PrecConstraint{j in Jobs,k in Jobs,

tu in p[j]..T-p[k]: (j,k) in Precedence}:sum{t in p[j]..tu}x[j,t] >= sum{t in p[j]+p[k]..tu + p[k]} x[k,t];

w jC  j

Page 5: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 5/31

Slide 5

AMPL Model for 1| prec |

minimize WCT:

sum{j in Jobs, t in p[j]..T} w[j] * t * x[j,t]; 

Corresponds to:

subject to TaskDone {j in Jobs}:

sum{t in p[j]..T} x[j,t] = 1; 

Corresponds to:

w jC  j

 x jt 

t  p  j

1  j

min w  j

t  p  j

 j1

n

tx  jt 

Page 6: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 6/31

Slide 6

AMPL Model for 1| prec |

subject to UnitWork {tu in 1..T}:

sum{j in Jobs, t in tu..tu+p[j]-1 inter p[j]..T} x[j,t] <= 1;

Corresponds to: 

subject to PrecConstraint{j in Jobs,k in Jobs,

tu in p[j]..T-p[k]: (j,k) in Precedence}:

sum{t in p[j]..tu}x[j,t] >= sum{t in p[j]+p[k]..tu + p[k]} x[k,t];

Corresponds to: 

w jC  j

 x ju 1u t 

t  p j 1

 j1

n

t  1,..., T  p j j1

n

 x ju

u1

xku

u1

t  pk 

0  J i J k , t  1,...,T  pk 

Page 7: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 7/31

Slide 7

More Complex Sets to Reduce IP size

# Transitive closure of precedence relations.set step{s in 1..ceil((n-1)/2)} dimen 2 :=

if s==1

then Precedence

else step[s-1] union setof {k in Jobs, (i,k) in step[s-1], (k,j) in step[s-1]} (i,j);

set TransPrec := step[ceil((n-1)/2)];

# Earliest finish time 

 param EFT{j in Jobs} := p[j] + sum{k in Jobs: (k,j) in TransPrec} p[k];

# Latest finish time 

 param LFT{j in Jobs} := T - sum{k in Jobs: (j,k) in TransPrec} p[k];# Possible finish times 

set FinishWindow{j in Jobs} := EFT[j]..LFT[j];

Page 8: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 8/31

Slide 8

Smaller, simpler formulation

var x {j in Jobs, t in FinishWindow[j]} binary;minimize WCT:

sum{j in Jobs, t in FinishWindow[j]} w[j] * t * x[j,t];

subject to TaskDone {j in Jobs}:

sum{t in FinishWindow[j]} x[j,t] = 1;

subject to UnitWork {tu in 1..T}:

sum{j in Jobs, t in tu..tu+p[j]-1 inter FinishWindow[j]} x[j,t] <= 1;

[Similar changes for precedence constraints]

Page 9: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 9/31

Slide 9

AMPL Data Files - Straightforward

 param n := 6; param p :=

0 8

1 2

2 1

3 3

4 12

5 1;

set Precedence :=

0 21 2

2 3

4 5;

Page 10: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 10/31

Slide 10

Use Sandia National Labs IP Solver: PICO

• Write cutting-plane and approximate-solution code using AMPL

variables

• Mapping transparent

Data

FilesSolver:

PICO

Exact

ComputeApproximate

Solution

IP

LPModel

Files

AMPL

Cutting Planes

Page 11: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 11/31

Slide 11

AMPL-PICO Interface

Standard AMPL interfaces

Customized PICO Interface

AMPL

SoftwareAMPL Model File

AMPL Problem

Specification Files

PICO

Executable

AMPL SolutionSpecification Files

AMPLSoftware

AMPL Solver Output

Unix ScriptsAMPL Model FileTailored PICO

C++ FilesC++ Compiler 

Tailored PICO

ExecutablePICO Output

Page 12: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 12/31

Slide 12

Caveats: Status as of June 22, 2004

• The derived classes are for branch and bound only (no cuts yet; notstable; but they’ll be there “soon”) 

• Only the serial version works as of this morning

 –  This could change by tomorrow

Page 13: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 13/31

Slide 13

Customized PICO Application

Goal: transparent access to AMPL variables from within problem-specificderivatives of core PICO application classes:

 –  MILP The “master” branching class 

 –  MILPNode The “worker” subproblem class 

 –  MILPProblem The problem definition class

• Creates a new namespace, so (as far as you’re concerned), these names

are the same.

• Maps multidimensional ampl variables to PICO’s linear variable space 

 –  Foo(1,2)

 –  Foo(bar(stuff),callFunc(moreStuff))

Page 14: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 14/31

Slide 14

How PICO Learns AMPL Names

• Variable names, constraint names –  Automatic (when the customized code is set up)

• Other parameters: list explicitly

 –  You may never use some helper parameters from the ampl file

# PICO SYMBOL: p n w EFT LFT T

Page 15: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 15/31

Slide 15

Example: Incumbent Heuristic for 1|prec|

Computing midpoints by stepping through valid x in lexicographic order 

w jC  j

DoubleVector frac(n());

IntVector time(n());

int curr_job = -1;

x_const_iterator curr = x_valid().begin();

x_const_iterator last = x_valid().end();

while (curr != last) {frac[curr->val1] += solution[x(*curr)]; 

if (frac[curr->val1] > 0.5) {

time[curr->val1] = curr->val2;

//

// Step past remaining jobs

//

curr_job = curr->val1;

while (curr->val1 == curr_job)

curr++;

}

else

curr++;

}

Page 16: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 16/31

Slide 16

Alternative Iteration

Computing midpoints

DoubleVector frac(n());

IntVector time(n());

for (int i=0;i< n(); i++){

for (int j=EFT(i) ; j<LFT(i) ; j++){

if (x_valid.isMember(i,j)){frac[i] += solution[x(i,j)]; 

if (frac[i] > 0.5) {

time[i] = j;

continue;

}

}

}

Page 17: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 17/31

Page 18: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 18/31

Slide 18

Another Example: computing objective

DoubleVector soln(n()); IntVector index(n()); 

order(time,index); // sorting

soln [0] = p(index[0]);

value = p(index[0]) * w(index[0]);for (int i=1; i< n(); i++) {

soln[index[i]] = soln[index[i-1]] + p(index[i-1]);

value += soln[index[i]] * w(index[i]);

}

Page 19: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 19/31

Slide 19

Incumbent Heuristics

• These code fragments would be part of the incumbentHeuristic() methodin MILPNode.

• If you find an incumbent, this method must call

globalPtr updateIncumbent(solution, solution value)

This is a PICO (1D) solution.

Page 20: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 20/31

Slide 20

A Customized PICO Application: A Simple Example

Command line:gen_milp_app test.mod test.dat

Generates:

test.col Column labelstest.row Row labels

test.val Values specified as PICO SYMBOLs

test.mps The MPS file for this application

test.map  A data file that describes the sets andsymbols defined by test.mod

Page 21: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 21/31

Slide 21

A Customized PICO Application: A Simple Example

Command line:gen_milp_app test.mod test.dat

Generates:

Makefile-test generates executableMakefile symbolic link to Makefile-test

test_info.{h,cpp} data structures to map ampl variables

test_milp.{h,cpp} derived classes for branching, nodes, etc.

test_extras.{h,cpp} for your custom methods (never deleted)

Where name.{h,cpp} means name.h and name.cpp

Page 22: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 22/31

Slide 22

Staged generation

• Stage 1 runs ampl to get row, column, val files, etc• Stage 2 generates the C++ files with derived milp classes

You can break this up:

gen_milp_app -stage 1 test.mod test.dat

Page 23: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 23/31

Slide 23

Syntactic Components in test.map

The AMPL/PICO interface dynamically identifies:• Sets: a collection a n-tuples.

 –  Sets of string literals: { aa, bb, cc, dd }

 –  Sets of integers: {1, 2, 3, 5, 7}

 –  Sets of n-tuples defined from other sets:

{(aa,1), (bb,2), (cc,3), (dd,5)}

• Symbols: any row or column label

Additional sets and data values are exported from AMPL by adding to

test.mod:

# PICO SYMBOLS: <symbol1> <symbol2> … 

Page 24: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 24/31

Slide 24

Editing the map file

• Index sets are read from ampl row/col files, not model files –  Cannot connect similar index sets

Set0(INT);

Set1(INT);

…. Set6(INT);

TaskDone[Set0];

UnitWork[Set1]

PrecConstraint[Set2, Set3, Set4];X[Set5, Set6];

Page 25: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 25/31

Slide 25

Editing the map file

• Clean up to reflect our knowledgeJobs(INT);

Time(INT);

TaskDone[Jobs];

UnitWork[Time]PrecConstraint[Jobs, Jobs, Time];

X[Jobs, Time];

Page 26: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 26/31

Slide 26

Protected Symbolic Access

Problem: the AMPL symbols may conflict with symbols in a the PICOclasses.

Solution:

• Access AMPL symbols only through the info() methodUse info p(j) instead of p(j)

• Enable protection by

 –  Compiling with the –DPROTECTED_APPINFO flag

 –  Running gen_milp_app with the–

protected-vars flag

Page 27: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 27/31

Slide 27

Using the Customized PICO Classes

By default gen_milp_app generates a generic main() function(parallel if you have configured with mpi, serial otherwise)

The following commands generate, compile and execute the PICO classes

gen_milp_app test.mod test.datmake all

test_milp test.mps

Page 28: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 28/31

Slide 28

Overriding Parameters

All parameters have default values. test_milp --help

Should output information about parameters you can override 

test_milp --debug=50 --useSets --preprocessIP=0 test.mps

If you don’t specify a value during the override, PICO will assume 1 

• Fine for binary parameters

• Parameters can have any type (probably effectively any built-in type)

Page 29: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 29/31

Slide 29

Generating Cutting Planes

• Conforms to Open Source Initiative (OSI) conventions

• Uses (and will contribute to) Cut Generation Library (CGL)

• Cuts are sparse (you have to build them)

Cut Generator 

PICO LPinterface

LP Solution

 picoRowCut

Page 30: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 30/31

Slide 30

ACRO

• acro-pico gives most of the pieces you need: pico, utilib, soplex, COIN• Configuration facility

• For this workshop, you can check out from a local cvs repository

• Example configuration

Sets up makfiles that link properly to local MPI libraries, cplex, etc

Configure --site=lafayette --without-mpi --with-clp --without-cplex --with-debugging

Page 31: Use Pico

7/28/2019 Use Pico

http://slidepdf.com/reader/full/use-pico 31/31

Slide 31

Comparison with ABACUS

A Branch And CUt SystemVariables and Constraints are C++ classes.

Variables must implement

double coeff(CONSTRAINT *c);

Constraints must implementdouble coeff(VARIABLE *v);

Flexible, reasonably quick development, but

• User manages mapping of individual variables to linear ordering• Cutting planes are accessed densely

• Have to compute the coefficients of all constraints, not just cuts