protected void AddConstraint(int t, IALPDecision a)//Add a column into RMP model { if (constraints[t].ContainsKey(a)) { return; } INumExpr exp1 = RMPModel.NumExpr(); if (t < Data.TimeHorizon - 1) { exp1 = RMPModel.Sum(Var2[t], RMPModel.Prod(-1, Var2[t + 1])); foreach (IALPResource re in Data.RS) { if (a.UseResource(re)) { exp1 = RMPModel.Sum(exp1, Var1[t][Data.RS.IndexOf(re)], RMPModel.Prod(Data.Qti(t, re, a) - 1, Var1[t + 1][Data.RS.IndexOf(re)])); } } } else { exp1 = RMPModel.Sum(exp1, Var2[t]); foreach (IALPResource re in Data.RS) { if (a.UseResource(re)) { exp1 = RMPModel.Sum(exp1, Var1[t][Data.RS.IndexOf(re)]); } } } constraints[t].Add(a, RMPModel.AddGe(exp1, Data.Rt(t, a))); }
protected void AddCol(int t, IALPDecision a)//Add a column into RMP model { if (var[t].ContainsKey(a)) { return; } //目标函数 Column col = RMPModel.Column(cost, Data.Rt(t, a)); //第一类约束 foreach (IALPResource re in Data.RS) { for (int k = t + 1; k < Data.TimeHorizon; k++) { col = col.And(RMPModel.Column(constraint1[k][Data.RS.IndexOf(re)], Data.Qti(t, re, a))); } if (a.UseResource(re)) { col = col.And(RMPModel.Column(constraint1[t][Data.RS.IndexOf(re)], 1)); } } //第二类约束 col = col.And(RMPModel.Column(constraint2[t], 1)); INumVar v = RMPModel.NumVar(col, 0, 1, NumVarType.Float); var[t].Add(a, v); }
protected void AddConstraint1(IALPDecision a) { if (Aggconstraints.ContainsKey(a)) { return; } lock (RMPModel) { INumExpr exp1 = RMPModel.NumExpr(); exp1 = RMPModel.Sum(AggVar2, RMPModel.Prod(-1, Var2[alpha + 1])); foreach (IALPResource re in Data.RS) { if (a.UseResource(re)) { exp1 = RMPModel.Sum(exp1, RMPModel.Prod((alpha + 1) * Data.Qti(alpha, re, a), AggVar1[Data.RS.IndexOf(re)])); } } Aggconstraints.Add(a, RMPModel.AddGe(exp1, (alpha + 1) * Data.Rt(alpha, a))); } }