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); } }
public static void UserEquilibrium(int tp, int dInfo, XXE_DataStructures.ProjectData project, NetworkData network, List <LinkData> links, List <ODdata> OD) { //FileInputOutput FileIO = new FileInputOutput(); 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.Add(newFL); //create the '0' index list entry, since loop starts with index '1' PathFL.Add(newPathFL); //create the '0' index list entry, since loop starts with index '1' //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; } } AllOrNothing(tp, dInfo, network.NumZones, network.NumNodes, FL, PathFL, network, links, OD, ref ShortPath); if (project.PrintDiagnosticResults == true) { XXE_Calculations.FileInputOutput.WriteDiagnosticsLinkFlows("AllOrNothing--Base", NFL, network.TotalLinks); } IterNum = 0; ObjFcn = 0; for (int i = 1; i <= network.TotalLinks; i++) { if (tp > 1) { ObjFcn = ObjFcn + LinkPerformanceCalculations.IntegratedTravTimeFcn(dInfo, links[i].Length, links[i].Capacity[tp], links[i].FreeFlowSpeed, FL[i], FLX[i], (network.PctUninformed[tp] / 100), links[i].Que[tp], LinkPerformanceCalculations.alphaInt[LinkPerformanceCalculations.CoeffIndex[i, tp]], LinkPerformanceCalculations.beta[LinkPerformanceCalculations.CoeffIndex[i, tp]]); } else { ObjFcn = ObjFcn + LinkPerformanceCalculations.IntegratedTravTimeFcn(dInfo, links[i].Length, links[i].Capacity[tp], links[i].FreeFlowSpeed, FL[i], FLX[i], (network.PctUninformed[tp] / 100), links[i].Que[tp - 1], LinkPerformanceCalculations.alphaInt[LinkPerformanceCalculations.CoeffIndex[i, tp]], LinkPerformanceCalculations.beta[LinkPerformanceCalculations.CoeffIndex[i, tp]]); } } for (int i = 1; i <= network.NumZones; i++) { for (int j = 1; j <= network.NumZones; j++) { ShortPath1[i, j] = ShortPath[i, j]; if (project.PrintDiagnosticResults == true) { XXE_Calculations.FileInputOutput.WriteDiagnosticsShortestPaths(i, j, ShortPath1); } } } ConvValue = 2 * network.ConvCrit; //initialize convergence value do { AllOrNothing(tp, dInfo, network.NumZones, network.NumNodes, NFL, NPathFL, network, links, OD, ref ShortPath); if (project.PrintDiagnosticResults == true) { XXE_Calculations.FileInputOutput.WriteDiagnosticsLinkFlows("AllOrNothing-Iteration", NFL, network.TotalLinks); } Bisection(tp, dInfo, 0, 1, network.ConvCrit, network, ref links); if (project.PrintDiagnosticResults == true) { XXE_Calculations.FileInputOutput.WriteDiagnosticsLinkFlows("Bisection", NFL, network.TotalLinks); } ConvValue = 0; ObjFcn = 0; for (int i = 1; i <= network.TotalLinks; i++) { if (tp > 1) { ObjFcn = ObjFcn + LinkPerformanceCalculations.IntegratedTravTimeFcn(dInfo, links[i].Length, links[i].Capacity[tp], links[i].FreeFlowSpeed, NFL[i], FLX[i], (network.PctUninformed[tp] / 100), links[i].Que[tp], LinkPerformanceCalculations.alphaInt[LinkPerformanceCalculations.CoeffIndex[i, tp]], LinkPerformanceCalculations.beta[LinkPerformanceCalculations.CoeffIndex[i, tp]]); } else { ObjFcn = ObjFcn + LinkPerformanceCalculations.IntegratedTravTimeFcn(dInfo, links[i].Length, links[i].Capacity[tp], links[i].FreeFlowSpeed, NFL[i], FLX[i], (network.PctUninformed[tp] / 100), links[i].Que[tp - 1], LinkPerformanceCalculations.alphaInt[LinkPerformanceCalculations.CoeffIndex[i, tp]], LinkPerformanceCalculations.beta[LinkPerformanceCalculations.CoeffIndex[i, tp]]); } 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]; } } //path flow for (int i = 1; i < NPathFL.Count; i++) { DeltaFlows = Math.Abs(NPathFL[i].Volume - PathFL[i].Volume); if (DeltaFlows != 0) { PathFL[i] = NPathFL[i]; } } ConvValue = ConvValue / network.TotalLinks; if (ConvValue <= network.ConvCrit) { SolutionConverged = true; } IterNum++; } while ((SolutionConverged == false) && (IterNum < network.MaxIterations)); }