1package com.gams.examples.warehouse;
4 import java.util.HashMap;
26 static int numberOfThreads = 16;
27 static int status = 0;
29 public static void main(String[] args) {
35 File workingDirectory =
new File(System.getProperty(
"user.dir"),
"Warehouse");
36 workingDirectory.mkdir();
44 resultDB.
addSet(
"supplyMap",3,
"Supply connection with level");
48 Object dbLock =
new Object();
49 Map<String, WarehouseThread> warehousesMap =
new HashMap<String, WarehouseThread>();
50 for (
int i=10; i<=numberOfThreads; i++) {
51 WarehouseThread wh =
new WarehouseThread(ws, i, resultDB, dbLock);
52 warehousesMap.put(Integer.toString(i), wh);
57 for (WarehouseThread wh : warehousesMap.values()) {
60 }
catch (InterruptedException e) {
67 }
catch (Exception e) {
83 static class WarehouseThread
extends Thread {
87 int numberOfWarehouses;
91 numberOfWarehouses = number;
101 opt.
defines(
"Warehouse", Integer.toString(numberOfWarehouses));
104 opt.
defines(
"disaggregate",
"0");
109 job.
run(opt, System.out);
112 synchronized (lockObject) {
117 if (supplyRec.getLevel() > 0.5)
118 synchronized (lockObject) {
119 String[] keys =
new String[] { Integer.toString(numberOfWarehouses), supplyRec.getKey(0), supplyRec.getKey(1) };
130 static String model =
131 "$title Warehouse.gms \n" +
134 "$SetDDList warehouse store fixed disaggregate // acceptable defines \n" +
135 "$if not set warehouse $set warehouse 10 \n" +
136 "$if not set store $set store 50 \n" +
137 "$if not set fixed $set fixed 20 \n" +
138 "$if not set disaggregate $set disaggregate 1 // indicator for tighter bigM constraint \n" +
139 "$ife %store%<=%warehouse% $abort Increase number of stores (>%warehouse) \n" +
141 "Sets Warehouse /w1*w%warehouse% / \n" +
142 " Store /s1*s%store% / \n" +
143 "Alias (Warehouse,w), (Store,s); \n" +
145 " fixed fixed cost for opening a warehouse / %fixed% / \n" +
147 " capacity(WareHouse) \n" +
148 " supplyCost(Store,Warehouse); \n" +
150 "$eval storeDIVwarehouse trunc(card(store)/card(warehouse)) \n" +
151 "capacity(w) = %storeDIVwarehouse% + mod(ord(w),%storeDIVwarehouse%);\n" +
152 "supplyCost(s,w) = 1+mod(ord(s)+10*ord(w), 100); \n" +
155 " open(Warehouse) \n" +
156 " supply(Store,Warehouse) \n" +
158 "Binary variables open, supply; \n" +
162 " oneWarehouse(s) \n" +
165 "defobj.. obj =e= sum(w, fixed*open(w)) + sum((w,s), supplyCost(s,w)*supply(s,w)); \n" +
167 "oneWarehouse(s).. sum(w, supply(s,w)) =e= 1; \n" +
169 "defopen(w).. sum(s, supply(s,w)) =l= open(w)*capacity(w); \n" +
171 "$ifthen %disaggregate%==1 \n" +
173 " defopen2(s,w); \n" +
174 "defopen2(s,w).. supply(s,w) =l= open(w); \n" +
177 "model distrib /all/; \n" +
178 "solve distrib min obj using mip; \n" +
179 "abort$(distrib.solvestat<>%SolveStat.NormalCompletion% or \n" +
180 " distrib.modelstat<>%ModelStat.Optimal% and \n" +
181 " distrib.modelstat<>%ModelStat.IntegerSolution%) 'No solution!'; \n" +
GAMSParameter getParameter(String identifier)
void defines(String defStr, String asStr)
void setSystemDirectory(String directory)
This example demonstrates how to solve a simple GAMS model to assign stores to warehouses for differe...
GAMSParameter addParameter(String identifier, int dimension)
GAMSSet addSet(String identifier, int dimension)
String workingDirectory()
GAMSDatabase addDatabase()
GAMSSet getSet(String identifier)
GAMSJob addJobFromString(String source)
void setWorkingDirectory(String directory)
static final String FILE_SEPARATOR
GAMSVariable getVariable(String identifier)
T addRecord(Vector< String > keys)
T findRecord(String ... keys)
void setAllModelTypes(String value)