public List <Pairing> GetFeasibleSolutionByMethod1() { //中间变量,用来传值 Node trip = new Node(); Pairing loopPath; int i, j; //Node s = NodeSet[0]; Topological2 topo; RCSPP R_C_SPP = new RCSPP(Net, out topo); //R_C_SPP.UnProcessed = new List<Node>(); //for (i = 0; i < Topo.Order.Count; i++) { // R_C_SPP.UnProcessed.Add(Topo.Order[i]); //} R_C_SPP.ShortestPath("Forward"); //R_C_SPP.UnProcessed = Topo.Order; //TODO:测试 2-24-2019 R_C_SPP.ShortestPath("Backward"); //for (i = 0; i < NodeSet.Count; i++) //{ // trip = NodeSet[i]; // trip.Visited = false; // if (trip.ID != 0 && trip.ID != -1) { // TripList.Add(trip); // } //} //也按拓扑顺序否?? while (LineList.Count > 0) { trip = LineList[0];//这里以 1,2,3...顺序寻路,使得许多路的大部分内容相同,可不可以改进策略 loopPath = FindFeasiblePairings(trip); LineList.RemoveAt(0); if (loopPath.Arcs == null) { throw new Exception("找不到可行回路!咋办啊!!"); } else { PathSet.Add(loopPath); for (i = 0; i < loopPath.Arcs.Count; i++) { trip = loopPath.Arcs[i].D_Point; for (j = 0; j < LineList.Count; j++) { if (LineList[j].ID == trip.ID) { //trip.Visited = true; LineList.RemoveAt(j); break; } } } } } PrepareInputForRMP(Net.TripList); return(this.PathSet); }
List <int> best_feasible_solution; //元素值为1的为决策变量的下标。只记录一个可行解,不管有多个目标值相同的解 #region //废弃auxiliary slack variables //ArrayList ExtraCovered ; //ArrayList Uncovered; //double[] Penalty; //double[] U; #endregion public CSP(NetWork network) { this.Network = network; NodeSet = network.NodeSet; TripList = network.TripList; Topological2 topo; R_C_SPP = new RCSPP(this.Network, out topo); }
List <int> best_feasible_solution; //元素值为1的为决策变量的下标。只记录一个可行解,不管有多个目标值相同的解 public CSP(NetWork network, int numOfCrew, int numOfRoute) { this.Network = network; NodeSet = network.NodeSet; TripList = network.TripList; Topological2 topo; R_C_SPP = new RCSPP(this.Network, out topo); NUMBER_CREW = numOfCrew; NUMBER_ROUTE = numOfRoute; }
List <int> best_feasible_solution; //元素值为1的为决策变量的下标。只记录一个可行解,不管有多个目标值相同的解 #region //废弃auxiliary slack variables //ArrayList ExtraCovered ; //ArrayList Uncovered; //double[] Penalty; //double[] U; #endregion public CSP(NetWork network) { this.Network = network; NodeSet = network.NodeSet; TripList = network.TripList; Topological2 topo; R_C_SPP = new RCSPP(this.Network, out topo); masterModel = new Cplex(); masterModel.SetParam(Cplex.Param.Simplex.Display, 0); masterModel.SetParam(Cplex.Param.MIP.Display, 0); //added 4-30 foreach (var trip in network.TripList) { if (task_dualPrice.ContainsKey(trip.LineID) == false) { task_dualPrice.Add(trip.LineID, new List <double>()); } //task_dualPrice[trip.LineID].Add(0); } }
public List <Pairing> GetFeasibleSolutionByPenalty() { Node trip = new Node(); Pairing Pairing; int i; Topological2 topo; RCSPP R_C_SPP = new RCSPP(Net, out topo); //TODO:测试 2-24-2019 //R_C_SPP.UnProcessed = new List<Node>(); //for (i = 0; i < Topo.Order.Count; i++) //{ // R_C_SPP.UnProcessed.Add(Topo.Order[i]); //} int M = 99999; R_C_SPP.ChooseCostDefinition(0); Arc arc; //迭代,直到所有trip被cover //while (LineList.Count > 0) while (LineIDList.Count > 0) { Console.Write(LineIDList.Count + ", "); R_C_SPP.ShortestPath("Forward"); R_C_SPP.FindNewPath(); Pairing = R_C_SPP.New_Column; PathSet.Add(Pairing); for (i = 1; i < Pairing.Arcs.Count - 2; i++) //起终点不用算 { arc = Pairing.Arcs[i]; //需还原pairing的Cost,减去 当前 增加的 M 的部分,即price if (arc.D_Point.numVisited > 0) { Pairing.Cost += arc.D_Point.Price; } arc.D_Point.numVisited++; arc.D_Point.Price = -arc.D_Point.numVisited * M; //第二天对应的复制点也要改变 if (CrewRules.MaxDays > 1)//&& arc.D_Point.StartTime < 1440) { for (int j = 0; j < NodeSet.Count; j++) { if (NodeSet[j].LineID == arc.D_Point.LineID && NodeSet[j].StartTime > arc.D_Point.StartTime) { NodeSet[j].numVisited++; NodeSet[j].Price = -NodeSet[j].numVisited * M; } } } //LineList.Remove(arc.D_Point); LineIDList.Remove(arc.D_Point.LineID); } } //还原trip的price foreach (var node in this.NodeSet) { node.numVisited = 0; node.Price = 0; } PrepareInputForRMP(Net.TripList); return(this.PathSet); }