protected override decimal GetIntrainSectionLinkCost(ITrainTrip train, IServiceSegment seg, decimal price) { decimal part1 = System.Convert.ToDecimal((seg.ArrTime - seg.DepTime).TotalMinutes) * _ctx.Vot; decimal part2 = -price * _ctx.BasicPriceDic[seg]; return(part1 * _cost_weight + _rev_weight * part2); }
protected override decimal GetIntrainStpLinkCost(ITrainTrip train, IStopStation stop, decimal price) { decimal part1 = System.Convert.ToDecimal((stop.DepTime - stop.ArrTime).TotalMinutes) * _ctx.Vot; decimal part2 = 0; return(part1 * _cost_weight + _rev_weight * part2); }
protected override decimal GetIntrainStpLinkCost(ITrainTrip train, IStopStation stop, decimal price) { decimal part1 = _objNet.CalIntrainStpLinkCost(train, stop, price); decimal part2 = _u * ((decimal)(stop.DepTime - stop.ArrTime).TotalMinutes * _ctx.Vot); return(part1 + part2); }
protected override decimal GetIntrainSectionLinkCost(ITrainTrip train, IServiceSegment seg, decimal price) { decimal part1 = _objNet.CalIntrainSectionLinkCost(train, seg, price); decimal part2 = _u * (_ctx.BasicPriceDic[seg] * price + ((decimal)(seg.ArrTime - seg.DepTime).TotalMinutes * _ctx.Vot)) + _LM_rho[seg]; return(part1 + part2); }
protected override decimal GetIntrainStpLinkCost(ITrainTrip train, IStopStation stop, decimal price) { return(0); }
protected override decimal GetIntrainSectionLinkCost(ITrainTrip train, IServiceSegment seg, decimal price) { return(-price * _ctx.BasicPriceDic[seg]); }
protected override decimal GetIntrainStpLinkCost(ITrainTrip train, IStopStation stop, decimal price) { return(System.Convert.ToDecimal((stop.DepTime - stop.ArrTime).TotalMinutes) * _ctx.Vot); }
protected override decimal GetIntrainSectionLinkCost(ITrainTrip train, IServiceSegment seg, decimal price) { return(System.Convert.ToDecimal((seg.ArrTime - seg.DepTime).TotalMinutes) * _ctx.Vot); }
public decimal CalIntrainStpLinkCost(ITrainTrip train, IStopStation stop, decimal price) { return(this.GetIntrainStpLinkCost(train, stop, price)); }
public decimal CalIntrainSectionLinkCost(ITrainTrip train, IServiceSegment seg, decimal price) { return(this.GetIntrainSectionLinkCost(train, seg, price)); }
//增加了拉格朗日乘子之后的LR-w网络 public static DirectedWeightedSparseGraph <string> BuildLRwGraph( DPNProblemContext ctx, DiscreteTimeAdapter adapter, ITrainTrip train, IRailwayStation station, Dictionary <CustomerArrival, List <TravelPath> > PathDict, Dictionary <IEdge <TravelHyperNode>, ITrainTrip> linkTrainDict, Dictionary <CustomerArrival, Dictionary <TravelPath, decimal> > LM_mu, //拉格朗日乘子 μ TODO:int 改为path , Dictionary <IEdge <TravelHyperNode>, decimal> LM_lambda) { DirectedWeightedSparseGraph <string> graph = new DirectedWeightedSparseGraph <string>(); //Build price_transfer links decimal[] priceLevelList = ctx.PriceLevelList.ToArray(); int last = 0; int interval = ctx.ControlInterval / adapter.Resolution; if (interval >= adapter.Horizon) { throw new Exception("控制频率应小于预售期"); } for (int level = 0; level < priceLevelList.Count(); level++) { for (int time = 0; time + interval < adapter.Horizon; time += interval) { decimal cost_part1 = ctx.Pal.Sum(c => PathDict[c].Where(path => path.StartStation == station && priceLevelList[level] == path.Price && linkTrainDict[path.ReservationArc] == train && time <= path.ReservationTime && time + interval > path.ReservationTime).Sum(p => LM_mu[c][p])); decimal cost_part2 = LM_lambda.Where(i => i.Key.Source.Station == station && i.Key.Destination.Price == priceLevelList[level] && linkTrainDict[i.Key] == train && time <= i.Key.Source.Time && time + interval > i.Key.Source.Time).Sum(i => i.Value); string selfnode = $"{priceLevelList[level]}_{time}"; //价格不变 string nextnode = $"{priceLevelList[level]}_{time + interval}"; if (!graph.HasVertex(selfnode)) { graph.AddVertex(selfnode); } if (!graph.HasVertex(nextnode)) { graph.AddVertex(nextnode); } if (!graph.AddEdge(selfnode, nextnode, cost_part1 - cost_part2)) { throw new Exception("存在相同的Edge"); } //上升一段 if (level < priceLevelList.Count() - 1) { string ariseNode = $"{priceLevelList[level + 1]}_{time + interval}"; if (!graph.HasVertex(ariseNode)) { graph.AddVertex(ariseNode); } if (!graph.AddEdge(selfnode, ariseNode, cost_part1 - cost_part2 + DpnAlgorithm.ASmallCost)) { throw new Exception("存在相同的Edge"); } } //下降一段 if (level > 0) { string decreaseNode = $"{priceLevelList[level - 1]}_{time + interval}";//价格等级默认是1 if (!graph.HasVertex(decreaseNode)) { graph.AddVertex(decreaseNode); } if (!graph.AddEdge(selfnode, decreaseNode, cost_part1 - cost_part2 - DpnAlgorithm.ASmallCost)) { throw new Exception("存在相同的Edge"); } } last = time + interval; } } //Build dummy nodes and links. string dummystart = $"Start";//价格等级默认是1 if (!graph.HasVertex(dummystart)) { graph.AddVertex(dummystart); } for (int level = 0; level < priceLevelList.Count(); level++) { string selfnode = $"{priceLevelList[level]}_0";//价格等级默认是1 if (!graph.AddEdge(dummystart, selfnode, (level + 1) * ASmallCost)) { throw new Exception("存在相同的Edge"); } } string dummyend = $"End";//价格等级默认是1 if (!graph.HasVertex(dummyend)) { graph.AddVertex(dummyend); } for (int level = 0; level < priceLevelList.Count(); level++) { string selfnode = $"{priceLevelList[level]}_{last}";//价格等级默认是1 if (!graph.AddEdge(selfnode, dummyend, ASmallCost)) { throw new Exception("存在相同的Edge"); } } var min = graph.Edges.Min(e => e.Weight); if (min <= 0) { foreach (var edge in graph.Edges) { edge.Weight += -min + DpnAlgorithm.ASmallCost; } } return(graph); }
protected virtual decimal GetIntrainStpLinkCost(ITrainTrip train, IStopStation stop, decimal price) { return((decimal)(stop.DepTime - stop.ArrTime).TotalMinutes * _ctx.Vot); }
protected virtual decimal GetIntrainSectionLinkCost(ITrainTrip train, IServiceSegment seg, decimal price) { return(_ctx.BasicPriceDic[seg] * price + (decimal)(seg.ArrTime - seg.DepTime).TotalMinutes * _ctx.Vot); }