public static void AllOrNothingMSA(int tp, int numZones, int numNodes, List <double> NFL, NetworkData network, List <LinkData> links, List <FreewayData> freewayfacilities, List <ODdata> OD, List <List <List <double> > > RampProportionList, List <List <ODvolume> > ODvolumeLists, ref double[,] SP1) { int I1, I2; int J, J1, J73; int N1, N2; ODvolumeLists.Clear(); List <double> SP = new List <double>(); //shortest path double newSP = new double(); SP.Add(newSP); //create the '0' index list entry, since loop starts with index '1' List <int> PrevNode = new List <int>(); //preceding node int newPrevNode = new int(); PrevNode.Add(newPrevNode); //create the '0' index list entry, since loop starts with index '1' NFL.Clear(); NFL.Add(newNFL); //create the '0' index list entry, since loop starts with index '1' for (int i = 1; i <= network.TotalLinks; i++) { NFL.Add(newNFL); NFL[i] = 0; if (links[i].PhysLink == true) { links[i].TravTime[tp] = HCM_FF_Method.TravTimeFcnFreewayFacilities(RampProportionList[i - 1], freewayfacilities[i - 1], tp, FL[i]); } ODvolumeLists.Add(new List <ODvolume>()); } for (int i = 1; i <= numZones; i++) { I1 = ODlink[i]; I2 = ODlink[i + 1] - 1; if (I1 > I2) { continue; } ShortestPathMSA(i, tp, ref PrevNode, ref SP, ref links, numNodes); for (int k = I1; k <= I2; k++) { J = DestZone[k]; //J = OD[k].DestZone; J73 = J - numZones; SP.Add(newSP); SP1[i, J73] = SP[J]; //SP1[i, OD[k].DestZone] = SP[J]; Line60 : PrevNode.Add(newPrevNode); J1 = PrevNode[J]; if (J1 == 0) { continue; } N1 = FS[J1]; N2 = FS[J1 + 1] - 1; for (int n = N1; n <= N2; n++) { if (links[n].ToNode == J) { NFL[n] = NFL[n] + OD[k].NumAdjTrips; ODvolume volume = new ODvolume(); volume.OrigZone = OD[k].OrigZone; volume.DestZone = OD[k].DestZone; volume.Volume = OD[k].NumAdjTrips; ODvolumeLists[n - 1].Add(volume); J = J1; goto Line60; //to-do: eventually remove } } } } }
public static void UserEquilibriumMSA(XXE_DataStructures.ProjectData project, NetworkData network, List <LinkData> links, List <FreewayData> freewayfacilities, List <ODdata> OD, List <UserEquilibriumTimePeriodResult> results, List <List <List <double> > > RampProportionList) { Graph g = new Graph(network.NumNodes - network.FirstNetworkNode + 1); ConstructGraph(g, links, network.FirstNetworkNode); int numTPs = 1; for (int n = 0; n < freewayfacilities.Count; n++) { if (freewayfacilities[n].PhysicalLinkXXE == true) { numTPs = freewayfacilities[n].TotalTimePeriods; } } UserEquilibriumTimePeriodResult timePeriodResult; for (int tp = 1; tp <= numTPs; tp++) { timePeriodResult = new UserEquilibriumTimePeriodResult(); Iteration iteration; double[,] ShortPath = new double[299, 299]; double[,] ShortPath1 = new double[299, 299]; double ObjFcn; //value of BPR function bool SolutionConverged = false; double DeltaFlows; double D; FL.Clear(); FL.Add(newFL); //create the '0' index list entry, since loop starts with index '1' List <List <ODvolume> > ODvolumeLists = new List <List <ODvolume> >(); //initialize shortest path from each origin to each destination to zero for (int i = 1; i <= network.NumZones; i++) { for (int j = 1; j <= network.NumZones + 1; j++) { ShortPath[j, i] = 0; ShortPath1[j, i] = 0; } } AllOrNothingMSA(tp, network.NumZones, network.NumNodes, FL, network, links, freewayfacilities, OD, RampProportionList, ODvolumeLists, ref ShortPath); IterNum = 0; ObjFcn = 0; for (int i = 1; i <= network.TotalLinks; i++) { ObjFcn = ObjFcn + HCM_FF_Method.TravTimeFcnFreewayFacilities(RampProportionList[i - 1], freewayfacilities[i - 1], tp, FL[i]); } for (int i = 1; i <= network.NumZones; i++) { for (int j = 1; j <= network.NumZones; j++) { ShortPath1[i, j] = ShortPath[i, j]; } } ConvValue = 2 * network.ConvCrit; //initialize convergence value do { IterNum++; AllOrNothingMSA(tp, network.NumZones, network.NumNodes, NFL, network, links, freewayfacilities, OD, RampProportionList, ODvolumeLists, ref ShortPath); MoveMSA(network, IterNum + 1); ConvValue = 0; ObjFcn = 0; List <double> TravelTimes = new List <double>(); for (int i = 1; i <= network.TotalLinks; i++) { double travelTime = HCM_FF_Method.TravTimeFcnFreewayFacilities(RampProportionList[i - 1], freewayfacilities[i - 1], tp, FL[i]); ObjFcn = ObjFcn + travelTime * FL[i]; //TravelTimes.Add(travelTime); DeltaFlows = Math.Abs(NFL[i] - FL[i]); //difference between previous set of flows and current set of flows if (DeltaFlows != 0) { D = NFL[i]; if (D == 0) { D = FL[i]; } ConvValue = ConvValue + DeltaFlows / D; FL.Add(newFL); FL[i] = NFL[i]; } TravelTimes.Add(HCM_FF_Method.TravTimeFcnFreewayFacilities(RampProportionList[i - 1], freewayfacilities[i - 1], tp, FL[i])); } ConvValue = ConvValue / network.TotalLinks; iteration = new Iteration(); iteration.ObjFunction = ObjFcn; iteration.IternationNum = IterNum; iteration.ConvergeValue = ConvValue; IterationLinkVolume linkVolume; for (int n = 1; n <= network.TotalLinks; n++) { if (links[n].PhysLink == true) { linkVolume = new IterationLinkVolume(); linkVolume.ID = n; linkVolume.FromNode = links[n].FromNode; linkVolume.ToNode = links[n].ToNode; linkVolume.Volume = FL[n]; linkVolume.PhysLink = links[n].PhysLink; iteration.LinkVolumes.Add(linkVolume); } } timePeriodResult.TimePeriod = tp; timePeriodResult.Iterations.Add(iteration); timePeriodResult.IsConverged = false; if (ConvValue <= network.ConvCrit || IterNum == network.MaxIterations) { if (ConvValue <= network.ConvCrit) { SolutionConverged = true; timePeriodResult.IsConverged = true; } timePeriodResult.NumIterations = IterNum; timePeriodResult.ConvergenceValue = ConvValue; timePeriodResult.ObjFunctionValue = ObjFcn; timePeriodResult.LinkResults.Clear(); LinkResult result; for (int n = 1; n <= network.TotalLinks; n++) { if (links[n].PhysLink == true) { result = new LinkResult(); result.ID = n; result.FromNode = links[n].FromNode; result.ToNode = links[n].ToNode; result.Volume = FL[n]; result.PhysLink = links[n].PhysLink; result.TravelTime = TravelTimes[n - 1]; result.VehMilesTravVolume = freewayfacilities[n - 1].Results[tp].VehMilesTravVolume; result.VehMilesTravDemand = freewayfacilities[n - 1].Results[tp].VehMilesTravDemand; result.VehHoursTrav = freewayfacilities[n - 1].Results[tp].VehHoursTrav; result.VehHoursDelay = freewayfacilities[n - 1].Results[tp].VehHoursDelay; result.DensityVeh = freewayfacilities[n - 1].Results[tp].DensityVeh; result.AvgSpeed = freewayfacilities[n - 1].Results[tp].AvgSpeed; result.DensityPC = freewayfacilities[n - 1].Results[tp].DensityPC; result.SegmentTravelTimes = GetSegmentTravelTimes(freewayfacilities[n - 1].TPsegs[tp]); if (freewayfacilities[n - 1].PhysicalLinkXXE == true) { result.FreeFlowTravelTime = freewayfacilities[n - 1].Results[tp].TravTimeFreeFlow; timePeriodResult.LinkResults.Add(result); } } } } } while ((SolutionConverged == false) && (IterNum < network.MaxIterations)); for (int od = 1; od < OD.Count; od++) //the first od item has no values { int PathFromNode = ZoneToNode(OD[od].OrigZone, links); int PathToNode = ZoneToNode(OD[od].DestZone, links); if (PathFromNode > 0 && PathToNode > 0) { g.PathList = new List <List <int> >(); GetPathsFromOD(g, PathFromNode, PathToNode, network.FirstNetworkNode); ODResult result = new ODResult(); result.Orig = OD[od].OrigZone; result.Dest = OD[od].DestZone; result.PathLists = g.PathList; result.TravelTimeList = GetPathTravelTimes(result.PathLists, timePeriodResult); result.FreeFlowTravelTimeList = GetPathFreeFlowTravelTimes(result.PathLists, timePeriodResult); double minimalPathTravelTime = result.TravelTimeList[0]; for (int n = 0; n < result.TravelTimeList.Count; n++) { if (result.TravelTimeList[n] < minimalPathTravelTime) { minimalPathTravelTime = result.TravelTimeList[n]; } } result.MinimalPathTravelTime = minimalPathTravelTime; double minimalPathFreeFlowTravelTime = result.FreeFlowTravelTimeList[0]; for (int n = 0; n < result.FreeFlowTravelTimeList.Count; n++) { if (result.FreeFlowTravelTimeList[n] < minimalPathFreeFlowTravelTime) { minimalPathFreeFlowTravelTime = result.FreeFlowTravelTimeList[n]; } } result.MinimalPathFreeFlowTravelTime = minimalPathFreeFlowTravelTime; for (int n = 0; n < result.TravelTimeList.Count; n++) { double diff = result.TravelTimeList[n] - minimalPathTravelTime; if (diff < 1) { result.UtilizedPathLists.Add(result.PathLists[n]); result.UtilizedList.Add(1); } else { result.UtilizedList.Add(0); } } timePeriodResult.ODResults.Add(result); } } results.Add(timePeriodResult); } }