Skip to content

Instantly share code, notes, and snippets.

@daynebatten
Created April 4, 2015 15:08
Show Gist options
  • Select an option

  • Save daynebatten/2991f9fba0e59f136126 to your computer and use it in GitHub Desktop.

Select an option

Save daynebatten/2991f9fba0e59f136126 to your computer and use it in GitHub Desktop.
/* Run the optimization */
proc optmodel;
set patterns = 1..&num_patterns;
set cuts = 1..&num_cuts;
number choices {patterns, cuts};
number prices {patterns};
number targets {cuts};
read data patterns into [i = _n_] {j in cuts} <choices[i,j] = col("choice"||j)>;
read data patterns into [i = _n_] prices[i] = col("price");
read data cuts into [i = _n_] targets[i] = col("number");
/* Selections will contain the patterns in the optimal solution */
var selections {patterns} integer;
/* Minimizing total cost... */
minimize total_cost = sum{p in patterns} prices[p] * selections[p];
/* Must cut enough of each length! */
con target_con {c in cuts}:
sum {p in patterns} selections[p] * choices[p, c] = targets[c];
/* And we can't select a negative number of any pattern... */
con not_negative {p in patterns}:
selections[p] >= 0;
solve with milp;
create data outdata from [i] = patterns col("chosen") = selections[i];
quit;
/* Clean up the result a bit */
data result;
set outdata;
set patterns;
if chosen > 0 then output;
keep choice1-choice7 lumber chosen;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment