private (Node, Node) GetSourceAndSink(GAMSDatabase gdxFile, Node[] nodes) { string src = gdxFile.GetSet(_str.SourceNode).FirstRecord().Keys[0]; string snk = gdxFile.GetSet(_str.SinkNode).FirstRecord().Keys[0]; Node sourceNode = nodes.FirstOrDefault(n => n.Label == src); Node sinkNode = nodes.FirstOrDefault(n => n.Label == snk); if (sourceNode == null || sinkNode == null) { throw new ArgumentException("Source/Sink not defined."); } return(sourceNode, sinkNode); }
private static void SolveWarehouse(GAMSWorkspace gmsWS, int NumberOfWarehouses, GAMSDatabase result, Object dbMutex) { // instantiate GAMSOptions and define some scalars GAMSOptions gmsOpt = gmsWS.AddOptions(); gmsOpt.AllModelTypes = "Gurobi"; gmsOpt.Defines.Add("Warehouse", NumberOfWarehouses.ToString()); gmsOpt.Defines.Add("Store", "65"); gmsOpt.Defines.Add("fixed", "22"); gmsOpt.Defines.Add("disaggregate", "0"); gmsOpt.OptCR = 0.0; // Solve to optimality // create a GAMSJob from string and write results to the result database GAMSJob gmsJ = gmsWS.AddJobFromString(GetModelText()); gmsJ.Run(gmsOpt); // need to lock database write operations lock (dbMutex) result.GetParameter("objrep").AddRecord(NumberOfWarehouses.ToString()).Value = gmsJ.OutDB.GetVariable("obj").FindRecord().Level; foreach (GAMSVariableRecord supplyRec in gmsJ.OutDB.GetVariable("supply")) { if (supplyRec.Level > 0.5) { lock (dbMutex) result.GetSet("supplyMap").AddRecord(NumberOfWarehouses.ToString(), supplyRec.Keys[0], supplyRec.Keys[1]); } } }
private static void PrintResults(GAMSDatabase db, int instanceIx, bool enforceOrigin) { string ostr = ""; ostr += $"Instance {instanceIx + 1} {(enforceOrigin ? "with" : "w/out")} enforced origin\n"; ostr += $"Delays {GDXUtils.GetLevelsStr(db.GetVariable("v"))}\n"; ostr += $"Costs:\t{db.GetVariable("f").FirstRecord().Level}\n"; int numGoods = db.GetSet("i").NumberRecords; int numComponents = db.GetSet("k").NumberRecords; var z = db.GetVariable("z"); var xint = db.GetVariable("xint"); var x = db.GetVariable("x"); var orders = GetOrders(db.GetVariable("w")); // first good is external source (not from disassembling but instead from order) for (int i = 1; i < numGoods; i++) { for (int k = 0; k < numComponents; k++) { int whenProvided = WhenProvided(x, i, k); ostr += $"i{i + 1},k{k + 1}: Provided at {whenProvided} "; int repairStart = GetRepairStart(z, i, k); if (repairStart >= 0) { ostr += $";; repair starts at {repairStart}"; } bool internallyProvided = InternallyProvided(xint, i, k); if (!internallyProvided) { Order o = orders.First(order => order.K == k); ostr += $";; ordered at {o.T}"; } ostr += "\n"; } } Console.WriteLine(ostr); }
private Node[] ReadNodes(GAMSDatabase gdxFile) { var n = gdxFile.GetSet(_str.NodeSet); var s = gdxFile.GetParameter(_str.StartTimes); var e = gdxFile.GetParameter(_str.EndTimes); Node[] nodes = new Node[n.NumberRecords]; double v = 0; double w = 0; int c = 0; foreach (GAMSSetRecord r in n) { var startTime = s.FindRecord(r.Keys); var endTime = s.FindRecord(r.Keys); v = (startTime != null) ? startTime.Value : 0.0; w = (endTime != null) ? endTime.Value : 0.0; ResourceConstraint[] constraint = new ResourceConstraint[] { new ResourceConstraint(v, w) }; nodes[c] = new Node(c, r.Keys[0], constraint, c, c); c++; } return(nodes); }
private static void SolveWarehouse(GAMSWorkspace gmsWS, int NumberOfWarehouses, GAMSDatabase result, Object dbMutex) { // instantiate GAMSOptions and define some scalars GAMSOptions gmsOpt = gmsWS.AddOptions(); gmsOpt.AllModelTypes = "Gurobi"; gmsOpt.Defines.Add("Warehouse", NumberOfWarehouses.ToString()); gmsOpt.Defines.Add("Store", "65"); gmsOpt.Defines.Add("fixed", "22"); gmsOpt.Defines.Add("disaggregate", "0"); gmsOpt.OptCR = 0.0; // Solve to optimality // create a GAMSJob from string and write results to the result database GAMSJob gmsJ = gmsWS.AddJobFromString(GetModelText()); gmsJ.Run(gmsOpt); // need to lock database write operations lock (dbMutex) result.GetParameter("objrep").AddRecord(NumberOfWarehouses.ToString()).Value = gmsJ.OutDB.GetVariable("obj").FindRecord().Level; foreach (GAMSVariableRecord supplyRec in gmsJ.OutDB.GetVariable("supply")) if (supplyRec.Level > 0.5) lock(dbMutex) result.GetSet("supplyMap").AddRecord(NumberOfWarehouses.ToString(), supplyRec.Keys[0], supplyRec.Keys[1]); }