Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 3.1 Basic Control Flow and Operators in the OPTMODEL Procedure 3.2 Model Updates in the OPTMODEL Procedure 3.3 Sensitivity Analysis and Parametric Programming.

Similar presentations


Presentation on theme: "1 3.1 Basic Control Flow and Operators in the OPTMODEL Procedure 3.2 Model Updates in the OPTMODEL Procedure 3.3 Sensitivity Analysis and Parametric Programming."— Presentation transcript:

1 1 3.1 Basic Control Flow and Operators in the OPTMODEL Procedure 3.2 Model Updates in the OPTMODEL Procedure 3.3 Sensitivity Analysis and Parametric Programming (Self-Study) 3.4 Network Flow Models Chapter 3: Linear Programming Problems: Additional Topics

2 2 3.1 Basic Control Flow and Operators in the OPTMODEL Procedure 3.2 Model Updates in the OPTMODEL Procedure 3.3 Sensitivity Analysis and Parametric Programming (Self-Study) 3.4 Network Flow Models Chapter 3: Linear Programming Problems: Additional Topics

3 3 Objectives Program simple routines using PROC OPTMODEL as an algebraic modeling language.

4 4 PROC OPTMODEL Programming Statements Control flow statements in PROC OPTMODEL should be familiar to users of the SAS DATA step: assignment (=) CONTINUE DO (blocks) DO (iterative) DO UNTIL DO WHILE FOR IF THEN IF THEN ELSE LEAVE null (;) STOP assignment (=) CONTINUE DO (blocks) DO (iterative) DO UNTIL DO WHILE FOR IF THEN IF THEN ELSE LEAVE null (;) STOP

5 5 PROC OPTMODEL Programming Statements FOR iterates over the members of an index set. assignment (=) CONTINUE DO (blocks) DO (iterative) DO UNTIL DO WHILE FOR IF THEN IF THEN ELSE LEAVE null (;) STOP assignment (=) CONTINUE DO (blocks) DO (iterative) DO UNTIL DO WHILE FOR IF THEN IF THEN ELSE LEAVE null (;) STOP num Dist{Origins,Destinations}; num Long{Cities}, Lat{Cities}; for {i in Origins} for {j in Destinations} /* calculate Dist[i,j] */ Task: Calculate the distances between all origin and destination locations.

6 6 PROC OPTMODEL Programming Statements FOR iterates over the members of an index set. assignment (=) CONTINUE DO (blocks) DO (iterative) DO UNTIL DO WHILE FOR IF THEN IF THEN ELSE LEAVE null (;) STOP assignment (=) CONTINUE DO (blocks) DO (iterative) DO UNTIL DO WHILE FOR IF THEN IF THEN ELSE LEAVE null (;) STOP num Dist{Origins,Destinations}; num Long{Cities}, Lat{Cities}; for {i in Origins} for {j in Destinations} /* calculate Dist[i,j] */ (There is a distance formula if Long and Lat are measured in radians.)

7 7 PROC OPTMODEL Programming Statements FOR iterates over the members of an index set. assignment (=) CONTINUE DO (blocks) DO (iterative) DO UNTIL DO WHILE FOR IF THEN IF THEN ELSE LEAVE null (;) STOP assignment (=) CONTINUE DO (blocks) DO (iterative) DO UNTIL DO WHILE FOR IF THEN IF THEN ELSE LEAVE null (;) STOP num Dist{Origins,Destinations}; num Long{Cities}, Lat{Cities}; for {i in Origins} do; x1 = Long[i]; y1 = Lat[i]; for {j in Destinations} if (i=j) then Dist[i,j]=0; else do; x2 = Long[j]; y2 = Lat[j]; Dist[i,j] = arcos(sin(y1)*sin(y2)+ cos(y1)*cos(y2)*cos(x2-x1))*3956; end;

8 8 PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN A B A DIFF B A B A UNION B A B A SYMDIFF B A B A INTER B

9 9 PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN 236 SLICE(,SET)={2,3,6}

10 10 PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN 236 {2,3,6} CROSS {1,2,4,5}

11 11 A PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN B C E D Network of Nodes and Arcs set Arcs = / /; set Nodes;

12 12 PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN B A C E D Network of Nodes and Arcs set Arcs = / /; set Nodes; Nodes = union{ in Arcs} {i,j};

13 13 PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN B A C E D Network of Nodes and Arcs and Paths of Arcs set Arcs = / /; set Nodes; set Paths; Nodes = union{ in Arcs} {i,j}; Paths = ???? Task: Find all nodes connected by paths.

14 14 PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN B A C E D Network of Nodes and Arcs set Arcs = / /; set Nodes; set Paths; Nodes = union{ in Arcs} {i,j}; Paths = Arcs; for {n in Nodes} Paths = Paths union ( slice(,Paths) cross slice(,Paths) );

15 15 A PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN B C E D Network of Nodes and Arcs set Arcs = / /; set Nodes; set Paths; Nodes = union{ in Arcs} {i,j}; Paths = Arcs; for {n in Nodes} Paths = Paths union ( slice(,Paths) cross slice(,Paths) );

16 16 B PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN A C E D Network of Nodes and Arcs set Arcs = / /; set Nodes; set Paths; Nodes = union{ in Arcs} {i,j}; Paths = Arcs; for {n in Nodes} Paths = Paths union ( slice(,Paths) cross slice(,Paths) );

17 17 B PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN A C E D set Arcs = / /; set Nodes; set Paths; Nodes = union{ in Arcs} {i,j}; Paths = Arcs; for {n in Nodes} Paths = Paths union ( slice(,Paths) cross slice(,Paths) ); Network of Nodes and Arcs and Paths of Arcs

18 18 C PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN B A E D Network of Nodes and Arcs and Paths of Arcs set Arcs = / /; set Nodes; set Paths; Nodes = union{ in Arcs} {i,j}; Paths = Arcs; for {n in Nodes} Paths = Paths union ( slice(,Paths) cross slice(,Paths) );

19 19 C PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN B A E D Network of Nodes and Arcs and Paths of Arcs set Arcs = / /; set Nodes; set Paths; Nodes = union{ in Arcs} {i,j}; Paths = Arcs; for {n in Nodes} Paths = Paths union ( slice(,Paths) cross slice(,Paths) );

20 20 D PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN B A C E Network of Nodes and Arcs and Paths of Arcs set Arcs = / /; set Nodes; set Paths; Nodes = union{ in Arcs} {i,j}; Paths = Arcs; for {n in Nodes} Paths = Paths union ( slice(,Paths) cross slice(,Paths) );

21 21 D PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN B A C E Network of Nodes and Arcs and Paths of Arcs set Arcs = / /; set Nodes; set Paths; Nodes = union{ in Arcs} {i,j}; Paths = Arcs; for {n in Nodes} Paths = Paths union ( slice(,Paths) cross slice(,Paths) );

22 22 E PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN B A C D set Arcs = / /; set Nodes; set Paths; Nodes = union{ in Arcs} {i,j}; Paths = Arcs; for {n in Nodes} Paths = Paths union ( slice(,Paths) cross slice(,Paths) ); Network of Nodes and Arcs and Paths of Arcs

23 23 PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN B A C E D Network of Nodes and Arcs and Paths of Arcs set Arcs = / /; set Nodes; set Paths; Nodes = union{ in Arcs} {i,j}; Paths = Arcs; for {n in Nodes} Paths = Paths union ( slice(,Paths) cross slice(,Paths) );

24 24 This demonstration illustrates some of the set operations available in PROC OPTMODEL to find the find all the nodes that are reachable by paths in a simple network of nodes and arcs. Computing Reachable Nodes Using PROC OPTMODEL reachable.sas

25 25 PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN num T = 5, Demand{1..T}; var Production{1..T}, Inventory{1..T-1}; con Inventory_Balance{i in 1..T}: Production[i] – Demand[i] = ???? 3 5 1 4 2 Production[i] Demand[i] Task: Formulate balance constraints.

26 26 3 5 1 4 2 PROC OPTMODEL Set and Logical Operators PROC OPTMODEL defines new types of expressions for the manipulation of sets, such as aggregation operators. AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN AND CARD CROSS DIFF IF THEN ELSE IN|NOT IN INTER MAX|MIN OR PROD|SUM SLICE SYMDIFF UNION WITHIN num T = 5, Demand{1..T}; var Production{1..T}, Inventory{1..T-1}; con Inventory_Balance{i in 1..T}: Production[i] – Demand[i] = if (i=1) then Inventory[1] else if (i=T) then – Inventory[T-1] else Inventory[i] – Inventory[i-1];

27 27 These exercises reinforce the concepts discussed previously. Exercises 1–2

28 28 3.1 Basic Control Flow and Operators in the OPTMODEL Procedure 3.2 Model Updates in the OPTMODEL Procedure 3.3 Sensitivity Analysis and Parametric Programming (Self-Study) 3.4 Network Flow Models Chapter 3: Linear Programming Problems: Additional Topics

29 29 Objectives Understand how the presolver simplifies linear programming problems. Be able to modify a linear programming problem (changing bounds or objective/constraint coefficients, fixing variables, adding variables or constraints) within the OPTMODEL procedure.

30 30 Automatic Updates: The Presolver Before solving a mathematical programming problem, the OPTMODEL presolver does the following: processes linear constraints to tighten bounds on variables converts simple bound constraints to bounds on variables eliminates constraints that are implied by variable bounds eliminates variables whose values are fixed

31 31 OPTMODEL Presolver Example Suppose that these are the constraints of the problem: 2x+y ≤ 6 2x+7y ≤ 14 x+y ≤ 5 x ≥ 0, y ≥ 0

32 32 OPTMODEL Presolver Example Suppose that these are the constraints of the problem: 2x+y ≤ 6 x ≤ (6-y)/2 ≤ 3 2x+7y ≤ 14 y ≤ (14-2x)/7 ≤ 2 x+y ≤ 5 x ≥ 0, y ≥ 0

33 33 OPTMODEL Presolver Example Suppose that these are the constraints of the problem: (The constraint x+y ≤ 5 is implied by the bounds.) 2x+y ≤ 6 x ≤ (6-y)/2 ≤ 3 2x+7y ≤ 14 y ≤ (14-2x)/7 ≤ 2 x+y ≤ 5 x ≥ 0, y ≥ 0 2x+y ≤ 6 2x+7y ≤ 14 0 ≤ x ≤ 3, 0 ≤ y ≤ 2

34 34 The OPTLP Presolver The LP solver has its own preprocessor, which can further reduce the size of the problem: OPTMODEL Presolver OPTLP Presolver LP

35 35 OPTMODEL/OPTLP Presolver Options OptionDescription AUTOMATICDefault setting (between moderate and aggressive) NONEDisable presolver BASICRemove empty constraints, substitute fixed variables MODERATEA higher level of preprocessing AGGRESSIVEHighest level of preprocessing PROC OPTMODEL PRESOLVER = option ; SOLVE WITH LP / PRESOLVER = option ;

36 36 This demonstration illustrates the effect of the PROC OPTMODEL and OPTLP presolvers on the organic potting soils product mix problem. The PROC OPTMODEL and OPTLP Presolvers product_mix.sas

37 37 Adding New Variables Recall: Tables require 3 hours of labor, 1 pound of metal, and 2 ft 3 wood. Tables sell for $55. The dual prices show that making tables is a profitable activity… … but how many should be produced? set Products, Resources; num Cost{Resources}, Availability{Resources}; num Selling_Price{Products}; num Requirements{Resources,Products}; Products = Products union /tables/;

38 38 Model Updates: Adding New Variables Recall: Tables require 3 hours of labor, 1 pound of metal, and 2 ft 3 wood. Tables sell for $55. The dual prices show that making tables is a profitable activity… … but how many should be produced? set Products, Resources; num Cost{Resources}, Availability{Resources}; num Selling_Price{Products}; num Requirements{Resources,Products}; Products = Products union /tables/; Selling_Price['tables']=55; Requirements['labor','tables']=3; Requirements['metal','tables']=1; Requirements['wood','tables']=2;

39 39 Reading Data for New Variables SAS Data Set: Work.New_Products set Products, Resources; num Cost{Resources}, Availability{Resources}; num Selling_Price{Products}; num Requirements{Resources,Products}; Products = Products union /tables/; read data New_Products into [Product] Selling_Price {r in Resources} ; ProductSelling_Pricelabormetalwood 1tables55312

40 40 This demonstration illustrates a simple way to add a new variable to a linear programming problem in PROC OPTMODEL. Adding a New Variable to an LP in PROC OPTMODEL furniture_tables.sas

41 41 Changing Variable/Constraint Bounds In the McDonald’s diet problem, suppose you want to add the restriction that at most two of each item can be included in the diet. Upper and lower bounds for variables and constraints can be modified and/or read from SAS data sets. Objective and constraint coefficients can also be modified, unless their values are assigned in a declaration statement. for {j in Food} x[j].ub = 2;

42 42 Fixing/Unfixing Variables What is the minimum cost diet with a Big Mac? The syntax is fix x['Big Mac'] = 1; FIX identifier-list [ =( expression ) ] ;

43 43 Fixing/Unfixing Variables What is the minimum cost diet with a Big Mac? The syntax is The effect can be reversed: FIX identifier-list [ =( expression ) ] ; UNFIX identifier-list [ =( expression ) ] ; fix x['Big Mac'] = 1;

44 44 Dropping/Restoring Constraints How much will the cost of the optimal diet decrease if there is no limit on sodium? The effect can be reversed with similar syntax: DROP|RESTORE identifier-expression; drop Diet['Sodium'];

45 45 Dropping/Restoring Constraints How much will the cost of the optimal diet decrease if there is no limit on sodium? The effect can be reversed with similar syntax: What will these statements do? drop Diet; restore Diet['Cal'] Diet['Protein']; drop Diet['Sodium']; DROP|RESTORE identifier-expression;

46 46 Adding Constraints Some ad hoc constraints would make the McDonald’s diet problem more realistic: Limit sauces by the number/size of McNuggets ordered (2 for 6 pieces; 3 for 9 pieces; 6 for 20 pieces). Limit salad dressings and toppings by the number of salads ordered. Require one drink per meal. At most 30% of the calories should be from fat (RDA requirement).

47 47 Re-optimizing in PROC OPTMODEL For many of these updates, it is more efficient to re-optimize, starting from the previous optimal solution: 2D LP

48 48 Re-optimizing in PROC OPTMODEL For many of these updates, it is more efficient to re-optimize, starting from the previous optimal solution: 2D LP 3D LP Re-optimizing (Primal Simplex)

49 49 The BASIS=WARMSTART Option To re-optimize, the presolvers should be disabled and the primal or dual simplex solver called: When the optimal solution is feasible for the new problem (adding variables, changing objective) use the primal simplex; otherwise (changing bounds, adding constraints), use the dual simplex. PROC OPTMODEL PRESOLVER=NONE; … SOLVE WITH LP / BASIS = WARMSTART PRESOLVER=NONE SOLVER=PS|DS; PROC OPTMODEL PRESOLVER=NONE; … SOLVE WITH LP / BASIS = WARMSTART PRESOLVER=NONE SOLVER=PS|DS;

50 50 Bogus OPTMODEL Program Structure What is wrong with this OPTMODEL program structure? proc optmodel presolver=none; /* declare sets and parameters */ /* declare variables */ /* declare constraints */ for {j in index-set} do; /* declare objective */ solve with lp / basis=warmstart presolver=none; /* print solution */ end; quit;

51 51 Corrected OPTMODEL Program Structure proc optmodel presolver=none; /* declare sets and parameters */ /* declare variables */ /* declare constraints */ /* declare objective */ for {j in index-set} do; parameter = j; solve with lp / basis=warmstart presolver=none; /* print solution */ end; quit;

52 52 This demonstration illustrates how PROC OPTMODEL can be used to re-optimize after making various updates to the McDonald’s diet problem. Re-Optimizing the McDonald’s Diet Problem in PROC OPTMODEL mcdonalds_reopt.sas

53 53 These exercises reinforce the concepts discussed previously. Exercises 3-4


Download ppt "1 3.1 Basic Control Flow and Operators in the OPTMODEL Procedure 3.2 Model Updates in the OPTMODEL Procedure 3.3 Sensitivity Analysis and Parametric Programming."

Similar presentations


Ads by Google