public override void StepFoward() { alpha -= step; //Delete Agg constraint(s) foreach (var a in Aggconstraints) { RMPModel.Remove(a.Value); } List <IALPDecision> list = Aggconstraints.Keys.ToList(); Aggconstraints.Clear(); //Add DisAgg variables and constraint(s) for (int i = alpha + 1; i <= alpha + step; i++) { constraints.Add(i, new Dictionary <IALPDecision, IRange>()); Var1.Add(i, RMPModel.NumVarArray(Data.RS.Count, 0, double.MaxValue)); Var2.Add(i, RMPModel.NumVar(0, double.MaxValue)); V.Add(i, new double[Data.RS.Count]); Sita.Add(i, 0); } for (int t = alpha + 1; t <= alpha + step; t++) { if (t < Data.TimeHorizon - 1) { foreach (IALPResource re in Data.RS) { INumExpr exp2 = RMPModel.Sum(Var1[t][Data.RS.IndexOf(re)], RMPModel.Prod(-1, Var1[t + 1][Data.RS.IndexOf(re)])); RMPModel.AddGe(exp2, 0); } INumExpr exp3 = RMPModel.Sum(Var2[t], RMPModel.Prod(-1, Var2[t + 1])); RMPModel.AddGe(exp3, 0); } } foreach (IALPResource re in Data.RS) { INumExpr exp6 = RMPModel.NumExpr(); exp6 = RMPModel.Sum(AggVar1[Data.RS.IndexOf(re)], RMPModel.Prod(-1, Var1[alpha + 1][Data.RS.IndexOf(re)])); RMPModel.AddGe(exp6, 0); } INumExpr exp4 = RMPModel.NumExpr(); exp4 = RMPModel.Sum(exp4, AggVar2, RMPModel.Prod(-1, Var2[alpha + 1])); RMPModel.AddGe(exp4, 0); foreach (IALPDecision de in list) { AddConstraint1(de); } Decision d = _ds[0] as Decision; for (int t = alpha + 1; t <= alpha + step; t++) { AddConstraint2(t, d); } }
private bool CG(int t, out IALPDecision deci_a) { deci_a = null; #region List <Product> list = (Data.ProSpace as List <Product>).Where(i => { double w = bidprice(t, i); if (i.Fare < w) { return(false); } else { return(true); } }).ToList(); List <Product> tempDecision = new List <Product>(); //加入第一个元素 Product tempProduct = null; double temp = computeValue(t, tempDecision, tempProduct); foreach (Product p in list) { if (temp < computeValue(t, tempDecision, p)) { temp = computeValue(t, tempDecision, p); tempProduct = p; } } if (tempProduct != null) { tempDecision.Add(tempProduct); list.Remove(tempProduct); } //贪婪方法加入其他元素 for (int length = 0; length < tempDecision.Count();) { length = tempDecision.Count(); foreach (Product p in list) { double temp1 = computeValue(t, tempDecision, p); if (temp < temp1) { temp = temp1; tempDecision.Add(p); } } } #endregion #region #region 得到 Route List //List<Route> list = Data.pathList.Where(i => //{ // double w = bidprice(t, i); // if (i.TicketPrice < w) // { // return false; // } // else // { // return true; // } //}).ToList(); //List<Route> tempRoutelist = new List<Route>(); //Route tempRoute = null; //double temp = computeValue(t, tempRoutelist, tempRoute); //foreach (Route r in list) //{ // if (temp < computeValue(t, tempRoutelist, r)) // { // temp = computeValue(t, tempRoutelist, r); // tempRoute = r; // } //} //if (tempRoute != null) //{ // tempRoutelist.Add(tempRoute); // list.Remove(tempRoute); //} ////贪婪方法加入其他元素 //for (int length = 0; length < tempRoutelist.Count();) //{ // length = tempRoutelist.Count(); // foreach (Route r in list) // { // double temp1 = computeValue(t, tempRoutelist, r); // if (temp < temp1) // { // temp = temp1; // tempRoutelist.Add(r); // } // } //} //#endregion //List<Product> tempDecision = new List<Product>(); //#region 找到一个u //foreach (Route r in tempRoutelist) //{ // foreach (Product p in r) // { // if (!tempDecision.Contains(p)) { tempDecision.Add(p); } // } //} #endregion #endregion //从u生成decision Decision d = new Decision(); d.OpenProductSet.UnionWith(tempDecision); lock (_ds) { deci_a = _ds.FirstOrDefault(k => (k as Decision).Equals(d)) as IALPDecision; if (deci_a == null) { _ds.Add(d); deci_a = d; } } if (computeValue(t, tempDecision, null) < Tolerance || (t > alpha ? constraints[t].ContainsKey(deci_a) : Aggconstraints.ContainsKey(deci_a))) { return(true); } else { return(false); } }