//function /*public override int[] EvaluationProcess(int ModelTimeofDay, int[] PreviousStage) * { * TimeSpan TS = new TimeSpan(0, 0, ModelTimeofDay / 100); * string TimeOfDay = TS.ToString(); * * bool Stochastic = false; * string[] Source = { "default" }; * double[] Xsig = { 0 }; * double[] Ysig = { 0 }; * double[] SenPC = { 0 }; * * FindStoch(ref Stochastic, ref Source, ref Xsig, ref Ysig, ref SenPC); * * NetDat.IVPextract(); * NetDat2.IVPextractWiggle(Source, Xsig, Ysig, SenPC);//TODO implement a check that Stochastic is "true". * NetDat2.LoopExtract(ModelTimeofDay, 10);//TODO unhardcode 10 second calc time (call in function) * * int[] CurrentStages = MainZone.NextStages;//TODO ad hoc code for setting the red light state for areas in the triangle model * * MainZone.CoordinateJunctions(ModelTimeofDay, PreviousStage); * * WriteBidsDatabase(ModelTimeofDay); * WriteSITDataBase(ModelTimeofDay, ref MainZone, (NetworkDataSIT)NetDat); * * //TODO ad hoc code for setting the red light state for areas in the triangle model * /*SitB.ClearRedSignals(); * if (CurrentStages != null) * { * for (int si = 0; si < 3; si++) * { * switch (si) * { * case 0: * switch (CurrentStages[si]) * { * case 1: * SitB.SetAreaRed("WS3A1"); * SitB.SetAreaRed("WS2A2"); * break; * case 2: * SitB.SetAreaRed("WS1A1"); * SitB.SetAreaRed("WS1A2"); * break; * case 3: * SitB.SetAreaRed("WS3A1"); * SitB.SetAreaRed("WS2A2"); * SitB.SetAreaRed("WS2A2"); * break; * } * break; * case 1: * switch (CurrentStages[si]) * { * case 1: * SitB.SetAreaRed("NS2A1"); * SitB.SetAreaRed("NS2A2"); * break; * case 2: * SitB.SetAreaRed("NS1A1"); * SitB.SetAreaRed("NS1A2"); * break; * } * break; * case 2: * switch (CurrentStages[si]) * { * case 1: * SitB.SetAreaRed("ES3A1"); * SitB.SetAreaRed("ES4A1"); * break; * case 2: * SitB.SetAreaRed("ES3A1"); * SitB.SetAreaRed("ES4A1"); * SitB.SetAreaRed("ES1A2"); * break; * case 3: * SitB.SetAreaRed("ES2A1"); * SitB.SetAreaRed("ES4A1"); * SitB.SetAreaRed("ES1A2"); * break; * case 4: * SitB.SetAreaRed("ES3A1"); * SitB.SetAreaRed("ES2A1"); * SitB.SetAreaRed("ES1A2"); * break; * } * break; * } * * } * }*/ //********************************************************************************/ //TODO hardcoding for HighRd Signal pattern /*SitB.ClearRedSignals(); * if (CurrentStages != null) * { * for (int si = 0; si < 2; si++) * { * switch (si) * { * case 0: * switch (CurrentStages[si]) * { * case 1: * SitB.SetAreaRed("WS3_A1"); * SitB.SetAreaRed("WS2_A1"); * SitB.SetAreaRed("WS3_A2"); * SitB.SetAreaRed("WS4_A1"); * break; * case 2: * SitB.SetAreaRed("WS1_A1"); * SitB.SetAreaRed("WS3_A1"); * SitB.SetAreaRed("WS3_A2"); * SitB.SetAreaRed("WS4_A1"); * break; * case 3: * SitB.SetAreaRed("WS1_A1"); * SitB.SetAreaRed("WS2_A1"); * break; * case 4: * SitB.SetAreaRed("WS1_A1"); * SitB.SetAreaRed("WS2_A1"); * SitB.SetAreaRed("WS3_A1"); * break; * } * break; * case 1: * switch (CurrentStages[si]) * { * case 1: * SitB.SetAreaRed("ES2_A1"); * SitB.SetAreaRed("ES3_A1"); * SitB.SetAreaRed("ES2_A2"); * break; * case 2: * SitB.SetAreaRed("ES3_A1"); * SitB.SetAreaRed("ES1_A1"); * break; * case 3: * SitB.SetAreaRed("ES1_A1"); * SitB.SetAreaRed("ES2_A2"); * break; * } * break; * } * } * }*/ //*********************************************************************************/ /*SitB.PullSensorData(ModelTimeofDay); * SitB.StateUpdate(ModelTimeofDay, NetDat2); * //writeSITdiffFiles(MainZone,SitB,@"Z:\visualizationBuffer"); * * * * return (MainZone.NextStages); * }*/ private void WriteSITDataBase(int ToD, ref ZoneAgent ZoneIn, NetworkDataSIT NDin) { TimeSpan TS = new TimeSpan(0, 0, ToD / 100); string TimeOfDay = TS.ToString(); int Znum = 0; foreach (JunctionAgent JA in ZoneIn.Junctions) { foreach (StageAgent SA in JA.Stages) { foreach (LaneAgent LA in SA.Lanes) { if (!LA.Duplicate) { if (LA.Count == 0) { NDin.SIT.AddSITLine(TimeOfDay, Znum, LA.Name, Convert.ToDouble(LA.Count), 13.41, LA.AvDist, "unknown");//TODO super hacky hardcode! get rid of this! } else { NDin.SIT.AddSITLine(TimeOfDay, Znum, LA.Name, Convert.ToDouble(LA.Count), LA.AvSpeed, LA.AvDist, "unknown"); } Znum++; } } } } }
public override void ConnectToParamics() { //Find out the number of agents and junctions int AgentNum = NetworkStruct.GetElementsByTagName("Agent").Count; int JunctionNum = NetworkStruct.GetElementsByTagName("Junction").Count; //NetDat = new NetworkDataSIT(ParamicsPath, IP, Port, AgentNum, JunctionNum, "Vehicledatasimple", "SITtrue"); NetDat = new NetworkDataSIT(ParamicsPath, IP, Port, AgentNum, JunctionNum, "LinkTurningMovements", "SITtrue"); NetDat2 = new NetworkDataSIT(ParamicsPath, IP, Port, AgentNum, JunctionNum, "VehicledataWobbly", "SITwobbly"); NetDat.PDB.ClearTableContents(); NetDat2.PDB.ClearTableContents(); NetDat2.LTB.ClearTableContents(); MainZone = new ZoneAgent(NetDat, Strat); WobblyZone = new ZoneAgent(NetDat2, Strat); FindAgents(NetDat, ref MainZone); FindAgents(NetDat2, ref WobblyZone); SitB = new SITbridge(NetDat2); FindSITAgents(NetDat2, ref SitB); SitB.AreaMash(); FindSensors(NetDat2, ref SitB);//TODO it is important that this is called after AreaMash() should probably put in acheck for this.... List <string> NodeNames = new List <string>(); foreach (JunctionAgent JA in MainZone.Junctions) { NodeNames.Add(JA.SignalNode); } SigSet = new SignalsSet(NetDat, NodeNames); }
private void GreedyNextStages(ZoneAgent ZA) { //int[] NextStages = new int[ZA.Junctions.Count]; List <int[]> NextStages = new List <int[]>(); //Note that I have removed ZA.Junctions.Count!!! for (int i = 0; i < ZA.Junctions.Count; i++) { NextStages = ZA.Junctions[i].NextStage; } ZA.NextStages = NextStages; }
//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); } }
private void writeSITdiffFiles(ZoneAgent ZoneIn, SITbridge SITin, String Path) { string[] countDiff = new string[SITin.getAreas().Count]; string[] speedDiff = new string[SITin.getAreas().Count]; int Znum = 0; foreach (JunctionAgent JA in ZoneIn.Junctions) { foreach (StageAgent SA in JA.Stages) { foreach (LaneAgent LA in SA.Lanes) { if (!LA.Duplicate) { foreach (SITarea theArea in SITin.getAreas()) { if (theArea.Area.name.Equals(LA.Name)) { if (LA.Count == 0) { countDiff[Znum] = theArea.Area.name + "," + Math.Round(Math.Abs(theArea.Area.stateNow.getNumberOfVehicles()) * 2).ToString(); speedDiff[Znum] = theArea.Area.name + "," + Math.Round((Math.Abs(13.41 - theArea.Area.stateNow.getAverageSpeedOfVehicles()))).ToString(); } else { countDiff[Znum] = theArea.Area.name + "," + Math.Round((Math.Abs(LA.Count - theArea.Area.stateNow.getNumberOfVehicles())) * 2).ToString(); speedDiff[Znum] = theArea.Area.name + "," + Math.Round((Math.Abs(LA.AvSpeed - theArea.Area.stateNow.getAverageSpeedOfVehicles()))).ToString(); } break; } } Znum++; } } } } File.WriteAllLines(Path + @"\diffCounts", countDiff); File.WriteAllLines(Path + @"\diffSpeeds", speedDiff); }
public virtual void ConnectToParamics() { //Find out the number of agents and junctions int AgentNum = NetworkStruct.GetElementsByTagName("Agent").Count * 3; //AH added times 3 to include all 12 phase bids int JunctionNum = NetworkStruct.GetElementsByTagName("Junction").Count; NetDat = new NetworkData(ParamicsPath, IP, Port, AgentNum, JunctionNum); NetDat.PDB.ClearTableContents(); MainZone = new ZoneAgent(NetDat, Strat); FindAgents(NetDat, ref MainZone); List <string> NodeNames = new List <string>(); foreach (JunctionAgent JA in MainZone.Junctions) { NodeNames.Add(JA.SignalNode); } SigSet = new SignalsSet(NetDat, NodeNames); }
public override void ProcessZone(ZoneAgent ZA, int ToD, int[] PreviousStage, Returner ReturnerVariables) { base.ProcessZone(ZA, ToD, PreviousStage, ReturnerVariables); }
public override void ProcessZone(ZoneAgent ZA, int ToD, int[] PreviousStage, Returner ReturnerVariables) { GreedyNextStages(ZA); }
public abstract void ProcessZone(ZoneAgent ZA, int ToD, int[] PreviousStage, Returner ReturnerVariables);