/* piece-wise linearization test based on John Mitchell example http://homepages.rpi.edu/~mitchj/handouts/piecewise/ a piece-wise linear cost function of a flow x is defined on 6 segments as follows: 0 <= x <= 2 cost: 0+2x 2 <= x <= 3 cost: -4+4x 3 <= x <= 5 cost: -10+6x 5 <= x <= 9 cost:-20+8x 9 <=x <= 15 cost: -35.03+9.67x 15 <= x <= 20 cost: -69.8+12x use the segmentation variables xi, yi. Ideally, CMPL would force the segmentation variables xi to be sos2, but that feature does not exist as yet, so need to use the yi approach from Mitchell example */ parameters: n:=7; breakpoints:=1..n; coefficient1[breakpoints]:=(0,2,3,5,9,15,20); coefficient2[breakpoints]:=(0,4,8,20,52,110.02,170.2); variables: xi[breakpoints]: real[0..]; yi[breakpoints]: binary; x:real[0..]; # this is set as a variable for eventual extension of this model to a production/consumption/transport model where the quantity transported will be a variable constraints: flow: x=20; # fix this value to any point in the range 0 <=x <= 20 to get to the proper lookup on piece-wise linear function totalflow: sum{i in breakpoints: xi[i]*coefficient1[i]}=x; # sos constraints sumofxi: sum{i in breakpoints:xi[i]}=1; # xi must sum to 1 sumofyi: sum{i in breakpoints:yi[i]}=2; # xi must sum to 2 xiltyi$ {i in breakpoints:xi[i]<=yi[i];} sos {j in 2..5: {i in 1..n-j:yi[i]+yi[i+j]<=1;}} # generalizing constraints on only allowing adjacent yi objectives: z: sum{i in breakpoints: xi[i]*coefficient2[i]}->min;