Benders2StageMT.cs
27 private static void ScenSolve(GAMSModelInstance subi, ref double cutconst, ref Dictionary<string, double> cutcoeff, Queue<Tuple<string, double, Dictionary<string, double>>> demQueue, ref double objsub, Object queueMutex, Object ioMutex)
47 Console.WriteLine(" Sub " + subi.ModelStatus + " : obj=" + subi.SyncDB.GetVariable("zsub").FirstRecord().Level);
54 cutconst += probability * subi.SyncDB.GetEquation("market").FindRecord(kv.Key).Marginal * kv.Value;
55 cutcoeff[kv.Key] += probability * subi.SyncDB.GetEquation("selling").FindRecord(kv.Key).Marginal;
90 GAMSParameter cutconst = masteri.SyncDB.AddParameter("cutconst", 1, "Benders optimality cut constant");
91 GAMSParameter cutcoeff = masteri.SyncDB.AddParameter("cutcoeff", 2, "Benders optimality coefficients");
92 GAMSVariable theta = masteri.SyncDB.AddVariable("theta", 0, VarType.Free, "Future profit function variable");
94 masteri.Instantiate("masterproblem max zmaster using lp", opt, new GAMSModifier(cutconst), new GAMSModifier(cutcoeff), new GAMSModifier(theta, UpdateAction.Fixed, thetaFix));
100 Queue<Tuple<string, double, Dictionary<string, double>>> demQueue = new Queue<Tuple<string, double, Dictionary<string, double>>>();
103 GAMSParameter received = subi[0].SyncDB.AddParameter("received", 1, "units received from first stage solution");
105 subi[0].Instantiate("subproblem max zsub using lp", opt, new GAMSModifier(received), new GAMSModifier(demand));
112 double lowerbound = double.NegativeInfinity, upperbound = double.PositiveInfinity, objmaster = double.PositiveInfinity;
124 Console.WriteLine(" Master " + masteri.ModelStatus + " : obj=" + masteri.SyncDB.GetVariable("zmaster").FirstRecord().Level);
127 objmaster = masteri.SyncDB.GetVariable("zmaster").FirstRecord().Level - theta.FirstRecord().Level;
134 demQueue.Enqueue(new Tuple<string, double, Dictionary<string, double>>(s.Key(0), scenarioData.FindRecord(s.Key(0), "prob").Value, demDict));
163 Parallel.For(0, numThreads, delegate(int i) { ScenSolve(subi[i], ref cons[i], ref coef[i], demQueue, ref objsub[i], queueMutex, ioMutex); });
void Instantiate(string modelDefinition, params GAMSModifier[] modifiers)
ModelStat ModelStatus
double Marginal
string Key(int index)
Dictionary< string, string > Defines
Definition: Benders2Stage.cs:8
new GAMSParameterRecord AddRecord(params string[] keys)
GAMSCheckpoint AddCheckpoint(string checkpointName=null)
string[] Keys
GAMSDatabase OutDB
GAMSParameter GetParameter(string parameterIdentifier)
string AllModelTypes
This example demonstrates a parallel implementation of a simple Benders decomposition method for a st...
Definition: Benders2StageMT.cs:26
GAMSOptions AddOptions(GAMSOptions optFrom=null)
UpdateAction
GAMSDatabase SyncDB
double Value
double Level
VarType
GAMSModelInstance AddModelInstance(string modelInstanceName=null)
new GAMSVariableRecord FirstRecord()
GAMSSet GetSet(string setIdentifier)
string Name
GAMSVariable GetVariable(string variableIdentifier)
bool Clear()
new GAMSEquationRecord FindRecord(params string[] keys)
new GAMSParameterRecord FindRecord(params string[] keys)
GAMSJob AddJobFromString(string gamsSource, GAMSCheckpoint checkpoint=null, string jobName=null)
void Solve(SymbolUpdateType updateType=SymbolUpdateType.BaseCase, TextWriter output=null, GAMSModelInstanceOpt miOpt=null)
GAMSParameter AddParameter(string identifier, int dimension, string explanatoryText="")
void Dispose()
SymbolUpdateType
GAMSVariable AddVariable(string identifier, int dimension, VarType varType, string explanatoryText="")
void Dispose()
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
GAMSEquation GetEquation(string equationIdentifier)