1package com.gams.examples.cutstock;
4import java.util.HashMap;
5import java.util.Iterator;
7import java.util.Map.Entry;
34 public static void main(String[] args) {
40 File workingDirectory =
new File(System.getProperty(
"user.dir"),
"Cutstock");
41 workingDirectory.mkdir();
52 opt.
defines(
"pmax", String.valueOf(maxpattern));
53 opt.
defines(
"solveMasterAs",
"RMIP");
56 Map<String, Double> d =
new HashMap<String, Double>();
58 d.put(
"i1", Double.valueOf(97) );
59 d.put(
"i2", Double.valueOf(610) );
60 d.put(
"i3", Double.valueOf(395) );
61 d.put(
"i4", Double.valueOf(211) );
63 Map<String, Double> w =
new HashMap<String, Double>();
65 w.put(
"i1", Double.valueOf(45) );
66 w.put(
"i2", Double.valueOf(36) );
67 w.put(
"i3", Double.valueOf(31) );
68 w.put(
"i4", Double.valueOf(14) );
79 for (String i : d.keySet())
81 for (Entry<String, Double> e : d.entrySet())
83 for (Entry<String, Double> e : w.entrySet())
89 masterInitJob.
run(opt, masterCP, cutstockData);
91 GAMSJob masterJob = ws.
addJobFromString(
"execute_load 'csdata', aip, pp; solve master min z using %solveMasterAs%;", masterCP);
93 GAMSSet pattern = cutstockData.
addSet(
"pp", 1,
"pattern index");
98 for (Entry<String, Double> e : w.entrySet()) {
99 String[] keys =
new String[] { e.getKey(), pattern.
addRecord( Integer.toString(++patternCount) ).
getKey(0) };
114 boolean patternAdded =
true;
117 masterJob.
run(opt, masterCP, cutstockData);
126 if (patternCount == maxpattern) {
127 System.out.println(
"Out of pattern. Increase maxpattern (currently ["+maxpattern+
"])");
128 patternAdded =
false;
134 if (y.getLevel() > 0.5) {
135 String[] keys =
new String[] { y.
getKey(0), s.
getKey(0) };
141 patternAdded =
false;
146 opt.
defines(
"solveMasterAs",
"MIP");
147 masterJob.
run(opt, cutstockData);
152 if (xp.getLevel() > 0.5) {
153 System.out.println(
" pattern ["+xp.getKey(0)+
"] ["+xp.getLevel()+
"] times: ");
155 @SuppressWarnings(
"unused")
157 Iterator<GAMSParameterRecord> it = param.
iterator();
158 while (it.hasNext()) {
160 System.out.println(
" ["+rec.
getKey(0)+
"] : ["+ rec.
getValue()+
"]");
162 System.out.println();
173 static String masterModel =
174 "$Title Cutting Stock - Master problem \n" +
185 "$if not set pmax $set pmax 1000 \n" +
186 "Set p possible patterns /1*%pmax%/ \n" +
187 " pp(p) dynamic subset of p \n" +
189 " aip(i,p) number of width i in pattern growing in p;\n" +
191 "* Master model \n" +
192 "Variable xp(p) patterns used \n" +
193 " z objective variable \n" +
194 "Integer variable xp; xp.up(p) = sum(i, d(i)); \n" +
196 "Equation numpat number of patterns used \n" +
197 " demand(i) meet demand; \n" +
199 "numpat.. z =e= sum(pp, xp(pp)); \n" +
200 "demand(i).. sum(pp, aip(i,pp)*xp(pp)) =g= d(i); \n" +
202 "model master /numpat, demand/; \n" +
205 static String subModel =
206 "$Title Cutting Stock - Pricing problem is a knapsack model \n" +
218 " demdual(i) duals of master demand constraint /#i eps/; \n" +
220 "Variable z, y(i) new pattern; \n" +
221 "Integer variable y; y.up(i) = ceil(r/w(i)); \n" +
223 "Equation defobj \n" +
226 "defobj.. z =e= 1 - sum(i, demdual(i)*y(i)); \n" +
227 "knapsack.. sum(i, w(i)*y(i)) =l= r; \n" +
228 "model pricing /defobj, knapsack/; \n" +
GAMSModelInstance addModelInstance()
GAMSParameter getParameter(String identifier)
GAMSSet addSet(String identifier, int dimension)
GAMSEquation getEquation(String identifier)
GAMSParameter addParameter(String identifier, int dimension)
GAMSVariable getVariable(String identifier)
void instantiate(String modelDefinition, GAMSModifier ... modifiers)
void defines(String defStr, String asStr)
void setAllModelTypes(String value)
void setValue(double value)
T findRecord(String ... keys)
T addRecord(Vector< String > keys)
void setSystemDirectory(String directory)
void setWorkingDirectory(String directory)
GAMSJob addJobFromString(String source)
GAMSCheckpoint addCheckpoint()
GAMSDatabase addDatabase()
This example implements a column generation approach.
Provides package namespace for Java interface and examples to General Algebraic Model System (GAMS).