SimpleCutstock.java
1package com.gams.examples.cutstock;
2
3import java.io.File;
4import java.util.HashMap;
5import java.util.Map;
6import java.util.Map.Entry;
7
12
19public class SimpleCutstock {
20
21 public static void main(String[] args) {
22 // check workspace info from command line arguments
24 if (args.length > 0)
25 wsInfo.setSystemDirectory( args[0] );
26 // create a directory
27 File workingDirectory = new File(System.getProperty("user.dir"), "SimpleCutstock");
28 workingDirectory.mkdir();
29 wsInfo.setWorkingDirectory(workingDirectory.getAbsolutePath());
30 // create a workspace
31 GAMSWorkspace ws = new GAMSWorkspace( wsInfo );
32
33 CutstockModel cs = new CutstockModel(ws);
34
35 // define input data
36 Map<String, Double> d = new HashMap<String, Double>();
37 {
38 d.put( "i1", Double.valueOf(97) );
39 d.put( "i2", Double.valueOf(610) );
40 d.put( "i3", Double.valueOf(395) );
41 d.put( "i4", Double.valueOf(211) );
42 }
43 Map<String, Double> w = new HashMap<String, Double>();
44 {
45 w.put( "i1", Double.valueOf(45) );
46 w.put( "i2", Double.valueOf(36) );
47 w.put( "i3", Double.valueOf(31) );
48 w.put( "i4", Double.valueOf(14) );
49 }
50 int r = 100; // raw width
51
52 cs.getRawWidth().addRecord().setValue( r );
53 for(String i : d.keySet())
54 cs.getWidths().addRecord(i);
55
56 for(Entry<String, Double> t : d.entrySet())
57 cs.getDemand().addRecord( t.getKey() ).setValue( t.getValue().doubleValue() );
58
59 for(Entry<String, Double> t : w.entrySet())
60 cs.getWidth().addRecord( t.getKey() ).setValue( t.getValue().doubleValue() );
61
62 cs.getOpt().setAllModelTypes( "cplex" );
63
64 try {
65 cs.run( System.out );
66 for(GAMSParameterRecord rep : cs.getPatRep())
67 System.out.println(rep.getKey(0) + ", pattern " + rep.getKey(1) + ": " + rep.getValue());
68 }
69 catch (GAMSException e) {
70 System.out.println("Problem in GAMS: " + e.getMessage());
71 return;
72 }
73 catch (Exception e) {
74 System.out.println("System Exception: " + e.getMessage());
75 return;
76 }
77 }
78}
GAMSSet getWidths()
get an input symbol, i : widths
Provides package namespace for Java interface and examples to General Algebraic Model System (GAMS)...
GAMSParameter getDemand()
get an input symbol, d : demand
This example implements a column generation approach.
&#160;
GAMSOptions getOpt()
get Options for the execution of the cutstock model
This example shows the wrapper model of a cutstock problem based on the simple GAMS [cutstock] model ...
void setSystemDirectory(String directory)
GAMSParameter getPatRep()
get an output symbol, patrep : Solution pattern report
GAMSParameter getRawWidth()
get an input symbol, r : raw width
T addRecord(Vector< String > keys)
void run()
Executes the cutstock model.
void setAllModelTypes(String value)
GAMSParameter getWidth()
get an input symbol, w : width
void setWorkingDirectory(String directory)