//Function to read get the agent data from the XML file protected void FindAgents(NetworkData NDin, ref ZoneAgent ZAin) { XmlNodeList JunctionsData = NetworkStruct.GetElementsByTagName("Junction"); foreach (XmlNode Jcn in JunctionsData) { string SignalNode = Jcn.SelectSingleNode("SignalNode").FirstChild.Value; int NumStages = Convert.ToInt32(Jcn.SelectSingleNode("Stages").FirstChild.Value); JunctionAgent TempJA = new JunctionAgent(NDin, Strat, SignalNode, NumStages); XmlNodeList StageData = Jcn.SelectNodes("Stage"); foreach (XmlNode Stg in StageData) { StageAgent TempSA = new StageAgent(NDin, Strat); XmlNodeList AgentData = Stg.SelectNodes("Agent"); foreach (XmlNode Agt in AgentData) { LaneAgent TempLA = new LaneAgent(NDin, Strat); TempLA.Duplicate = Convert.ToBoolean(Agt.SelectSingleNode("Duplicate").FirstChild.Value); TempLA.Name = Agt.SelectSingleNode("name").FirstChild.Value; //TempLA.UpstreamAgents = Agt.SelectSingleNode("UpstreamAgents").FirstChild.Value; XmlNodeList RoadData = Agt.SelectNodes("RoadSec"); foreach (XmlNode Rsec in RoadData) { string Snode, Enode; int Lane, OLanes; double Oset; Snode = Rsec.SelectSingleNode("StartNode").FirstChild.Value; Enode = Rsec.SelectSingleNode("EndNode").FirstChild.Value; Lane = Convert.ToInt32(Rsec.SelectSingleNode("Lane").FirstChild.Value); OLanes = Convert.ToInt32(Rsec.SelectSingleNode("OfLanes").FirstChild.Value); Oset = Convert.ToDouble(Rsec.SelectSingleNode("Offset").FirstChild.Value); TempLA.RoadSegments.Add(new LaneAgent.BitOfRoad(Snode, Enode, Lane, OLanes, Oset)); } TempSA.Lanes.Add(TempLA); } TempSA.NeutralWeight(); TempJA.Stages.Add(TempSA); } ZAin.Junctions.Add(TempJA); } }
public override void ProcessJunction(JunctionAgent JA, int[] PreviousStage, Returner ReturnerVariables) { //test that number of stages and agents match JA.AllRoadStates.Clear(); if (JA.Stages.Count != JA.NoOfStages) { throw (new Exception("The number of stages does not match the number of agents")); } for (int i = 0; i < JA.Stages.Count; i++) { JA.AllRoadStates.Add(JA.Stages[i].RoadStates); } int WinningStage = 1; //This is where AH adds his stage selector... AllStages AS = new AllStages(); List <List <int> > AllPossibleStages = new List <List <int> >(); //Number of Stages - Reads a file to generate stage list //AllPossibleStages = AS.ReturnAllCrossroadStages(); //AllPossibleStages = AS.StagesGenerator(@"OptimalCrossroad17Stages.txt"); //This is for the 17 stage option //AllPossibleStages = AS.StagesGenerator(@"OptimalCrossroad16Stages.txt"); //This is for the 16 stage option //AllPossibleStages = AS.StagesGenerator(@"OptimalCrossroad12Stages.txt"); //This is for the 12 stage option //AllPossibleStages = AS.StagesGenerator(@"OptimalCrossroad8Stages.txt"); //This is for the 8 stage option //Console.WriteLine(PreviousStage); //Four stage road state model [Stage1RoadState, State2RoadState...] //List<double[]> FourStageRoadStates = new List<double[]>(); //FourStageRoadStates = ReturnFourStageSolution(JA.AllRoadStates); //12 Phase road state model [Phase1RoadState, Phase2RoadState...] List <double[]> TwelvePhaseRoadStates = new List <double[]>(); TwelvePhaseRoadStates = Return12PhaseRoadState(JA.AllRoadStates); List <int[]> CyclePlan = new List <int[]>(); CyclePlan.Clear(); double NumberOfVehicles = ReturnNumberOfVehicles(TwelvePhaseRoadStates); /*if (NumberOfVehicles >= FixedVariables.MaxNumberOfVehiclesAtJunction) //This is a way of using a fixed time cycle if the number of cars exceeds a certain value.... * { * Console.WriteLine("There are this many cars..." + NumberOfVehicles); * CyclePlan = FixedTimePlan(PreviousStage[0]); * Console.WriteLine("Stage " + CyclePlan[0][0] + " called for " + CyclePlan[0][1] + "seconds"); * }*/ if (NumberOfVehicles <= FixedVariables.MinNumberOfVehiclesAtJunction) { FixedVariables.MaximumGreenTime = FixedVariables.MaxGreenTimeLowFlow; } else { FixedVariables.MaximumGreenTime = FixedVariables.MaxGreenTimeNormalFlow; } if (false) { } else { FixedVariables FV = new FixedVariables(); RunnerCyclePlan RunCyclePlan = new RunnerCyclePlan(); //4 Stage Model //CyclePlan = RunCyclePlan.RunAlgorithm(FV.StartingSeeds, FV.StepsClimbed, FV.MutationsAroundAPoint, TwelvePhaseRoadStates, RunCyclePlan.PopulatePhasesFourStageModel()); //8 Stage Model //CyclePlan = RunCyclePlan.RunAlgorithm(FV.StartingSeeds, FV.StepsClimbed, FV.MutationsAroundAPoint, TwelvePhaseRoadStates, RunCyclePlan.PopulatePhasesEightStageModel()); //17 Stage Model //CyclePlan = RunCyclePlan.RunAlgorithm(FV.StartingSeeds, FV.StepsClimbed, FV.MutationsAroundAPoint, TwelvePhaseRoadStates, RunCyclePlan.PopulatePhasesSeventeenStageModel()); //RunnerSingleStage RunSS = new RunnerSingleStage(); RunnerAllSingleStageOptions RunAllSS = new RunnerAllSingleStageOptions(); //8 Stage - Single Stage Selection Model //CyclePlan = RunSS.RunAlgorithm(FV.StartingSeeds, FV.StepsClimbed, FV.MutationsAroundAPoint, TwelvePhaseRoadStates, PreviousStage[0], RunCyclePlan.PopulatePhasesEightStageModel()); //CyclePlan = RunAllSS.RunAlgorithm(TwelvePhaseRoadStates, PreviousStage[0], RunCyclePlan.PopulatePhasesEightStageModel()); //NB. In 'RunAllSS' there is a function which would not need to be used in 4 stage model - UpdateDischargeRate8Stage //4 Stage - Single Stage Selection Model - All Combinations checked CyclePlan = RunAllSS.RunAlgorithm(TwelvePhaseRoadStates, PreviousStage[0], RunCyclePlan.PopulatePhasesFourStageModel(), ReturnerVariables.TimeSinceReleased); UpdateTimeSinceReleased(CyclePlan, RunCyclePlan.PopulatePhasesFourStageModel(), ReturnerVariables); //NB. In 'RunAllSS' there is a function which would not need to be used in 4 stage model - UpdateDischargeRate8Stage //8 Stage - Single Stage Selection Model - All Combinations checked if demand //CyclePlan = RunAllSS.RunAlgorithm(TwelvePhaseRoadStates, PreviousStage[0], RunCyclePlan.PopulatePhasesEightStageModel(), ReturnerVariables.TimeSinceReleased); //UpdateTimeSinceReleased(CyclePlan, RunCyclePlan.PopulatePhasesEightStageModel(), ReturnerVariables); //17 Stage - Single Stage Selection Model - All Combinations checked //CyclePlan = RunAllSS.RunAlgorithm(TwelvePhaseRoadStates, PreviousStage[0], RunCyclePlan.PopulatePhasesSeventeenStageModel()); //2 Stage - Single Stage Selection Model - All Combinations checked //CyclePlan = RunAllSS.RunAlgorithm(TwelvePhaseRoadStates, PreviousStage[0], RunCyclePlan.PopulatePhasesTwoStageModel()); } List <int[]> FinalAnswer = new List <int[]>(); //This is to remove the (99,5) Intergreen Phase FinalAnswer.Clear(); FinalAnswer = ReturnCyclePlan(CyclePlan); JA.NextStage = FinalAnswer; //This all works for the highbid model... /*int LastStage = 2; * LastStage = PreviousStage[0]; * * //Stage Choice - Select the 'logic' for choosing the best stage * //Console.WriteLine(LastStage); * //WinningStage = AS.WithinXPercentStage(AllPossibleStages, JA.AllPhases, LastStage, 15.0); //This is for the within "X" percent bid * * WinningStage = AS.SimpleHighestStage(AllPossibleStages, JA.AllPhases); //This is for the basic highest bid * * List<int[]> Answer = new List<int[]>(); * int[] SingleStage = new int[2]; * int StageLength = 10; * SingleStage[0] = WinningStage; * SingleStage[1] = StageLength; * Answer.Add(SingleStage); * * JA.NextStage = Answer; * * /*int Stage = 1; * double BidHolder = 0; * foreach (StageAgent SA in JA.Stages) * { * Bid B = SA.StageBid; * if (B.Scalar > BidHolder) //This is Simon's original stage selection process * { * WinningStage = Stage; * BidHolder = B.Scalar; * } * Stage++; * }*/ //JA.NextStage = WinningStage;*/ }
public abstract void ProcessJunction(JunctionAgent JA, int[] PreviousStage, Returner ReturnerVariables);