reset; ######## Sets ######## set A0 := {0,4,3,5,6,7,1}; set A1 := {1..10 by 1}; set A2 := {1..10 by 0.5}; set A3 := (A1 diff A2) union {0}; set A4 := {i in A1: i mod 3 = 0 or i < 9}; set A {i in 1..5}:= union{j in 1..i^2 by 0.2} {round(j,2)}; set B default {}; for {i in 1..10} let B:=B union {round(Uniform(0,20))}; #display A0,A1,A2,A3,A4; display A; display B; #end; ######## Parameter ######## param a := Normal(0,1); param b default 0; let b := a+1; param f{i in 0..10} := if i=0 then 1 else i*f[i-1]; # to do: binomial coefficients?? param c1{i in A1} := Uniform(0,1); param c1_mean := 1/card{A1} * sum{i in A1} c1[i]; param c1_var := 1/card{A1} * sum{i in A1} (c1[i]-c1_mean)^2; param c2{i in A1,j in A2} := Uniform(0,1); param c2_mean {j in A2}:= 1/card{A1} * sum{i in A1} c2[i,j]; param c2_var {j in A2}:= 1/card{A1} * sum{i in A1} (c2[i,j]-c2_mean[j])^2; #display a,b; display c1,c1_mean, c1_var; display c1,c2_mean, c2_var; #end; ######## Data ######### param d {1..5}; param d2{1..5,1..3}; param d3{1..5,1..3,1..2}; set D; data; set D := 1,3,5,27,17; param d := 1 45 2 74 3 82 4 17 5 3; param d2 : 1 2 3 := 1 45 34 23 2 74 38 28 3 82 33 27 4 17 31 29 5 3 35 25; param d3 [*,*,1]: 1 2 3 := 1 45 34 23 2 74 38 28 3 82 33 27 4 17 31 29 5 3 35 25 [*,*,2]: 1 2 3 := 1 55 24 93 2 64 48 78 3 72 63 77 4 87 71 89 5 93 85 75; model; display D,d; display d2; display d3; #end; ######## Variables ######### var x0; var x1 >= 0; var x2 >= 2; var x3 >= 2,<=5, integer; var x4 := 2; var x5 binary; var x6 integer; var x7 = x5*x6; var x{i in 1..10}; #end; ######## Objectives ######## minimize LP1: 2*x1 + 3*x2; minimize LP2{i in 1..5}: i*x1 + 3*x2; minimize LP3: sum{i in 1..10} x[i]; minimize LP4: sum{i in 1..10} x[i]^2; ###### Constraints subject to NB1: 2*x2 <= 25-x1; subject to NB2: 4*x2 >= 2*x1-8; subject to NB3: x2 <= 2*x1-5; subject to NB4: sum{i in 1..10} x[i] >= 1; ###### Solver option solver cplex; solve; display x1,x2; objective LP2[3]; solve; display x1,x2,LP2; printf"x1=%4.2f, x2=%4.3f\n\n", x1, x2; # data for multiple parameters (see above) # multiple objectives (optimize one objective, display all) # neos example (see course page)