SimpleCutstock.cs
1using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using GAMS;
6 
7 namespace Cutstock
8 {
17  {
18  static void Main(string[] args)
19  {
20  GAMSWorkspace ws;
21  if (Environment.GetCommandLineArgs().Length > 1)
22  ws = new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]);
23  else
24  ws = new GAMSWorkspace();
25 
26  Cutstock cs = new Cutstock(ws);
27 
28  Dictionary<string, double> d =
29  new Dictionary<string, double>() { { "i1", 97 }, { "i2", 610 }, { "i3", 395 }, { "i4", 211 } };
30  Dictionary<string, double> w =
31  new Dictionary<string, double>() { { "i1", 47 }, { "i2", 36 }, { "i3", 31 }, { "i4", 14 } };
32  int r = 100; // raw width
33 
34  cs.RawWidth.AddRecord().Value = r;
35  foreach (string i in d.Keys)
36  cs.Widths.AddRecord(i);
37  foreach (KeyValuePair<string, double> t in d)
38  cs.Demand.AddRecord(t.Key).Value = t.Value;
39  foreach (KeyValuePair<string, double> t in w)
40  cs.Width.AddRecord(t.Key).Value = t.Value;
41 
42  cs.Opt.AllModelTypes = "cplex";
43 
44  try
45  {
46  cs.Run(Console.Out);
47  foreach (GAMSParameterRecord rep in cs.PatRep)
48  {
49  Console.WriteLine(rep.Key(0) + ", pattern " + rep.Key(1) + ": " + rep.Value);
50  }
51  }
52  catch (GAMSException e)
53  {
54  Console.WriteLine("Problem in GAMS: " + e.Message);
55  return;
56  }
57  catch (System.Exception e)
58  {
59  Console.WriteLine("System Error: " + e.Message);
60  return;
61  }
62  }
63  }
64 }
string Key(int index)
This example implements a column generation approach to solve the cutting stock problem....