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 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 } } } } }