public static void Bisection(int tp, int dInfo, double min, double max, double convCrit, NetworkData network, ref List <LinkData> links) { double mid = (min + max) / 2; //root of equation, alpha value double D; double TempFlow; double ObjFcn; NFL.Add(newNFL); //create the '0' index list entry, since loop starts with index '1' //mid = (min + max) / 2; while (max - min > convCrit) { D = 0; for (int i = 1; i <= network.TotalLinks; i++) { TempFlow = FL[i] + mid * (NFL[i] - FL[i]); if (tp > 1) { ObjFcn = LinkPerformanceCalculations.TravTimeFcn(dInfo, links[i].Length, links[i].Capacity[tp], links[i].FreeFlowSpeed, TempFlow, FLX[i], (network.PctUninformed[tp] / 100), links[i].Que[tp - 1], LinkPerformanceCalculations.alpha[LinkPerformanceCalculations.CoeffIndex[i, tp]], LinkPerformanceCalculations.beta[LinkPerformanceCalculations.CoeffIndex[i, tp]]); } else { ObjFcn = LinkPerformanceCalculations.TravTimeFcn(dInfo, links[i].Length, links[i].Capacity[tp], links[i].FreeFlowSpeed, TempFlow, FLX[i], (network.PctUninformed[tp] / 100), links[i].Que[tp], LinkPerformanceCalculations.alpha[LinkPerformanceCalculations.CoeffIndex[i, tp]], LinkPerformanceCalculations.beta[LinkPerformanceCalculations.CoeffIndex[i, tp]]); } D = D + ObjFcn * (NFL[i] - FL[i]); } if (D > 0) { max = mid; } else { min = mid; } mid = (min + max) / 2; } for (int i = 1; i <= network.TotalLinks; i++) { NFL.Add(newNFL); NFL[i] = FL[i] + mid * (NFL[i] - FL[i]); } //update the path flows as well to get one set of path flow solutions for (int i = 1; i < NPathFL.Count; i++) { NPathFL[i].Volume = PathFL[i].Volume + mid * (NPathFL[i].Volume - PathFL[i].Volume); } }
public static int DriverInfo; //loop variable for informed and uninformed drivers (uninformed = 1, informed = 2)] public static void RunControl(XXE_DataStructures.ProjectData Project, NetworkData network, List <LinkData> links, List <FreewayData> freewayfacilities, List <ODdata> ODpairs, List <UserEquilibriumTimePeriodResult> Results, List <List <List <double> > > RampProportionList) { network.TotTravTime = 0; network.TotVMT = 0; network.TotVC = 0; NonZeroFlowLinks = 0; TotPhysLinks = 0; FLX.Add(newFLX); //create the '0' index list entry, since loop starts with index '1' //FileInputOutput FileIO = new FileInputOutput(); if (Project.PrintDiagnosticResults == true) { XXE_Calculations.FileInputOutput.OpenDiagnosticsOutput(Project.Title); } if (network.TimePeriodType == TimePeriod.Single) { DriverInfo = 1; XXE_Calculations.FileInputOutput.OpenResultsFile(Project.Title); } else { DriverInfo = 2; XXE_Calculations.FileInputOutput.OpenTimePeriodResultsFile(Project.Title); } LinkPerformanceCalculations.InitializeBPRparms(); if (Project.Type == ProjectType.FreewayFacilities) { GenerateCorrespondingLinks(freewayfacilities, links); } GetLinkAssignments(network, links, ODpairs); DeterminePhysicalLinks(network, links); if (Project.Type == ProjectType.FreewayFacilities) { for (int j = 1; j <= network.NumODrecords; j++) { ODpairs[j].NumAdjTrips = Convert.ToInt64(ODpairs[j].NumTrips); } for (int n = 1; n <= network.TotalLinks; n++) { FLX.Add(newFLX); FLX[n] = 1; } UserEquilibriumMSA(Project, network, links, freewayfacilities, ODpairs, Results, RampProportionList); } else { for (int timePer = 1; timePer <= network.NumTimePeriods; timePer++) { for (int drvInfo = 1; drvInfo <= DriverInfo; drvInfo++) { if (Project.PrintDiagnosticResults == true) { XXE_Calculations.FileInputOutput.WriteDiagnosticsTimePeriod(timePer, drvInfo); } for (int j = 1; j <= network.NumODrecords; j++) { if (drvInfo == 1) { ODpairs[j].NumAdjTrips = Convert.ToInt64(ODpairs[j].NumTrips * network.IntensityRatio[timePer]); } else { ODpairs[j].NumAdjTrips = Convert.ToInt64(ODpairs[j].NumTrips * (1 - (network.PctUninformed[timePer] / 100)) * network.IntensityRatio[timePer]); } if (Project.PrintDiagnosticResults == true) { XXE_Calculations.FileInputOutput.WriteDiagnosticsODtrips(j, ODpairs[j].NumAdjTrips); } } for (int n = 1; n <= network.TotalLinks; n++) { if (drvInfo == 1) { FLX.Add(newFLX); FLX[n] = 1; links[n].Capacity[timePer] = links[n].Capacity[0]; //uninformed drivers do not know about capacity reductions } else { FLX.Add(newFLX); FLX[n] = FL[n]; links[n].Capacity[timePer] = links[n].Capacity[0] * links[n].PropCap[timePer]; //XXEXQ Fortran version sets a lower bound to the link capacity ratio of 0.1 } LinkPerformanceCalculations.SelectBPRcoeffsIndex(links[n].FreeFlowSpeed, links[n].Capacity[timePer], n, timePer); if (Project.PrintDiagnosticResults == true) { XXE_Calculations.FileInputOutput.WriteDiagnosticsLinkCapacities(n, links[n].Capacity[timePer]); } } //if 100% of drivers are uninformed, then skip assignment for informed drivers if (!(drvInfo == 2 && network.PctUninformed[timePer] == 100)) { UserEquilibrium(timePer, drvInfo, Project, network, links, ODpairs); } if (network.TimePeriodType == TimePeriod.Multiple) { CalcMultiTimePeriodPerformanceMeasures(timePer, drvInfo, network, links); } } } if (network.TimePeriodType == TimePeriod.Single) { CalcSingleTimePeriodPerformanceMeasures(network, links); for (int n = 1; n <= network.TotalLinks; n++) { if (network.PrintCentroidConnectors == true) { XXE_Calculations.FileInputOutput.WriteLinkResults(n, NFL[n], links[n].Capacity[1], links[n].vcRatio[1], links[n].FromNode, links[n].ToNode, links[n].TravTime[1], links[n].Description); } else { if (links[n].PhysLink == true) { XXE_Calculations.FileInputOutput.WriteLinkResults(n, NFL[n], links[n].Capacity[1], links[n].vcRatio[1], links[n].FromNode, links[n].ToNode, links[n].TravTime[1], links[n].Description); } } } } else //(NetworkData.TimePeriodType == TimePeriod.Multiple) { PrintTimePeriodData(network, ref links); } XXE_Calculations.FileInputOutput.WriteNetworkResults(network, NonZeroFlowLinks); } }
public static void CalcMultiTimePeriodPerformanceMeasures(int tp, int drvInfo, NetworkData network, List <LinkData> links) { double TravTime; double UninformedTrafficVol, LinkVol; double CITY; if (drvInfo == 1) { //can 'NFL[i]' be substituted for 'BEI[i]' in line 381? for (int i = 1; i <= network.TotalLinks; i++) { BEI[i] = NFL[i]; } } if (drvInfo == 1 && network.PctInformed[tp] > 0) { return; } for (int i = 1; i <= network.TotalLinks; i++) //Do 9012 loop in Fortran code { UninformedTrafficVol = BEI[i] * (1 - network.PctInformed[tp] / 100); LinkVol = NFL[i]; if (network.PctUninformed[tp] == 100) { LinkVol = 0; } links[i].Flow[tp] = UninformedTrafficVol + LinkVol; //Link[i].Capacity[tp] = Convert.ToInt64(Link[i].Capacity[tp]) * Link[i].PropCap[tp]; links[i].Que[tp] = 0; CITY = network.TravTimeAdjRatio * links[i].Capacity[tp]; if (tp == 1) { TravTime = LinkPerformanceCalculations.TravTimeFcn(2, links[i].Length, CITY, links[i].FreeFlowSpeed, links[i].Flow[tp], 0, 0, links[i].Que[tp], LinkPerformanceCalculations.alpha[LinkPerformanceCalculations.CoeffIndex[i, tp]], LinkPerformanceCalculations.beta[LinkPerformanceCalculations.CoeffIndex[i, tp]]); } else { TravTime = LinkPerformanceCalculations.TravTimeFcn(2, links[i].Length, CITY, links[i].FreeFlowSpeed, links[i].Flow[tp], 0, 0, links[i].Que[tp - 1], LinkPerformanceCalculations.alpha[LinkPerformanceCalculations.CoeffIndex[i, tp]], LinkPerformanceCalculations.beta[LinkPerformanceCalculations.CoeffIndex[i, tp]]); } if (tp > 1) { if (links[i].Flow[tp] > links[i].Capacity[tp] || links[i].Que[tp - 1] != 0) { links[i].Que[tp] = Math.Max(links[i].Que[tp - 1] + (links[i].Flow[tp] - links[i].Capacity[tp]) / (Convert.ToDouble(network.NumTimePeriods) / 2.0), 0); if (links[i].Que[tp - 1] < 0) { links[i].Que[tp - 1] = 0; } } } //**line 9013 in the course notes appears as the line just after line 8313 in the Fortran code received from Fred else { if (links[i].Flow[tp] > links[i].Capacity[tp]) { links[i].Que[tp] = Math.Max((links[i].Flow[tp] - links[i].Capacity[tp]) / (Convert.ToDouble(network.NumTimePeriods) / 2.0), 0); } } if (tp == 1) { links[i].vcRatio[tp] = links[i].Flow[tp] / links[i].Capacity[tp]; } else { links[i].vcRatio[tp] = (links[i].Flow[tp] + links[i].Que[tp - 1]) / links[i].Capacity[tp]; } if (drvInfo == 2 && links[i].PhysLink == true) //compute network statistics { network.TotTravTime = network.TotTravTime + TravTime * links[i].Flow[tp] / (Convert.ToDouble(network.NumTimePeriods) / 2.0); network.TotVMT = network.TotVMT + links[i].Length * links[i].Flow[tp] / (Convert.ToDouble(network.NumTimePeriods) / 2.0); if (links[i].vcRatio[tp] < 5) { network.TotVC = network.TotVC + links[i].vcRatio[tp]; } else { network.TotVC = network.TotVC + 5; } if (tp == network.NumTimePeriods) { network.AvgVCallPhysLinks = network.TotVC / network.NumTimePeriods / TotPhysLinks; //Network.AvgVCnonZeroFlowLinks = Network.TotVC / NonZeroFlowLinks; } } } }
public static void AllOrNothing(int tp, int dInfo, int numZones, int numNodes, List <double> NFL, List <PathData> NPathFL, NetworkData network, List <LinkData> links, List <ODdata> OD, ref double[,] SP1) { int I1, I2; int J, J1, J73; int N1, N2; //double[] SP = new double[600]; //shortest path //int[] PrevNode = new int[600]; //preceding node 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' NPathFL.Clear(); NPathFL.Add(newNPathFL); GetAllPaths(NPathFL, network, links, OD); for (int i = 1; i <= network.TotalLinks; i++) { NFL.Add(newNFL); NFL[i] = 0; if (tp > 1) { links[i].TravTime[tp] = LinkPerformanceCalculations.TravTimeFcn(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.alpha[LinkPerformanceCalculations.CoeffIndex[i, tp]], LinkPerformanceCalculations.beta[LinkPerformanceCalculations.CoeffIndex[i, tp]]); } else { links[i].TravTime[tp] = LinkPerformanceCalculations.TravTimeFcn(dInfo, links[i].Length, links[i].Capacity[tp], links[i].FreeFlowSpeed, FL[i], FLX[i], (network.PctUninformed[tp] / 100), links[i].Que[tp], LinkPerformanceCalculations.alpha[LinkPerformanceCalculations.CoeffIndex[i, tp]], LinkPerformanceCalculations.beta[LinkPerformanceCalculations.CoeffIndex[i, tp]]); } /* * if (tp > 1) * { * string message = Convert.ToString(tp) + "," + Convert.ToString(dInfo) + "," + Convert.ToString(i) + "," + Convert.ToString(Link[i].Capacity[tp]) + "," + Convert.ToString(FL[i]) + "," + Convert.ToString(FLX[i]) + "," + Convert.ToString(Network.PctUninformed[tp] / 100) + "," + Convert.ToString(Link[i].Que[tp - 1]) + "," + Convert.ToString(Link[i].TravTime[tp]); * //string message = Convert.ToString(tp) + "," + Convert.ToString(i) + "," + Convert.ToString(Link[i].Capacity[tp]) + "," + Convert.ToString(FL[i]) + "," + Convert.ToString(FLX[i]) + "," + Convert.ToString(Network.PctUninformed[tp] / 100) + "," + Convert.ToString(Link[i].Que[tp - 1]) + "," + Convert.ToString(Link[i].TravTime[tp]); * Debug.WriteLine(message); * } * else * { * string message = Convert.ToString(tp) + "," + Convert.ToString(dInfo) + "," + Convert.ToString(i) + "," + Convert.ToString(Link[i].Capacity[tp]) + "," + Convert.ToString(FL[i]) + "," + Convert.ToString(FLX[i]) + "," + Convert.ToString(Network.PctUninformed[tp] / 100) + "," + Convert.ToString(Link[i].Que[tp]) + "," + Convert.ToString(Link[i].TravTime[tp]); * Debug.WriteLine(message); * }*/ } for (int i = 1; i <= numZones; i++) { I1 = ODlink[i]; I2 = ODlink[i + 1] - 1; if (I1 > I2) { continue; } ShortestPath(i, tp, dInfo, 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]; AssignVolumeToShortestPath(NPathFL, i, J73, numZones, PrevNode, OD[k].NumAdjTrips); /* * if (tp == 7 && dInfo == 2) * { * string message = "SP: " + Convert.ToString(i) + "," + Convert.ToString(J73) + "," + Convert.ToString(SP[J]); * Debug.WriteLine(message); * for (int z = 1; z <= 17; z++) * { * if (TempLink[z] != 0) * { * Debug.WriteLine(Convert.ToString(TempLink[z]) + "," + Convert.ToString(TempTravTime[z])); * } * } * }*/ 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; J = J1; goto Line60; //to-do: eventually remove } } } } }
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)); }