public override void DoCalculate()//Calculate the Bid-Price of current time { print("------{0} Attemping with [Alpha = {1}]", System.DateTime.Now.ToLongTimeString(), alpha); bool IsOptimal = true; double tempObj = 0; int tol = ObeyTime; for (int iter = 1; ; iter++) { //print("------{0} Starting iteration:{1}", System.DateTime.Now.ToLongTimeString(), iter); if (RMPModel.Solve()) { #region 判断是否终止 if (RMPModel.GetObjValue() - tempObj < Threshold) { tol--; } else { tol = ObeyTime; } tempObj = RMPModel.GetObjValue(); #endregion } print("------{0} Starting iteration:{1},Current Obj Value:{2}", System.DateTime.Now.ToLongTimeString(), iter, tempObj); UpdateValues(); #region 判断是否终止 if (tol < 0) { print("--------{0} Attemping Completed!iter:{1}", System.DateTime.Now.ToLongTimeString(), iter); print("--------{0}算法达到终止条件而退出--------", System.DateTime.Now.ToLongTimeString()); UpdateBidPrice(); break; } #endregion IsOptimal = SolveSubProblem(); if (IsOptimal) { print("--------{0} Attemping Completed!iter:{1}", System.DateTime.Now.ToLongTimeString(), iter); UpdateValues(); UpdateBidPrice(); break; } } SendEvent(new IterationCompletedEventArgs() { Alpha = alpha, BidPrice = this.BidPrice, ObjValue = tempObj, TurnningPoint = findturnningpoint() }); }
public override void DoCalculate()//Calculate the Bid-Price of current time { CreateFeasibleSolution(); bool IsOptimal = true; double tempObj = 0; int tol = ObeyTime; for (int iter = 1; ; iter++) { IsOptimal = true; if (RMPModel.Solve()) { #region 判断是否终止 if (RMPModel.GetObjValue() - tempObj < threshold) { tol--; } else { tol = ObeyTime; } tempObj = RMPModel.GetObjValue(); #endregion } UpdateValues(); #region 判断是否终止 if (tol < 0) { print("--------{0}算法达到终止条件而退出--------", System.DateTime.Now.ToLongTimeString()); UpdateBidPrice(); break; } #endregion //for (int t = CurrentTime; t < Data.TimeHorizon; t++) //{ // IALPDecision deci_a = null; // bool IsSubOpt = CG(t, out deci_a); // if (!IsSubOpt) // { // AddConstraint(t, deci_a); // } // IsOptimal = IsSubOpt && IsOptimal; //} for (int iteration = CurrentTime; iteration < Data.TimeHorizon; iteration++) { int t = iteration; Task ta = factory.StartNew(() => { IALPDecision deci_a = null; bool IsSubOpt = CG(t, out deci_a); if (!IsSubOpt) { lock (RMPModel) { AddConstraint(t, deci_a); } } IsOptimal = IsSubOpt && IsOptimal; //print("#{0}第{1}个子问题已经解决!", System.DateTime.Now.ToLongTimeString(), iteration); }, cts.Token); tasks.Add(ta); } Task.WaitAll(tasks.ToArray()); tasks.Clear(); if (IsOptimal) { print("--------已经达到最优!", System.DateTime.Now.ToLongTimeString()); UpdateValues(); UpdateBidPrice(); SA(); break; } } }