public List<IntelligentRoundabout> GetPossibleSolutionsForNextIter(Roundabout roundaboutState) { var conflicts = FindConflictPoints(); switch (conflicts.Count) { case 0: return new List<IntelligentRoundabout>() { GetStateWithParams(new Dictionary<int, ConflictResolution>()) }; case 1: return new List<IntelligentRoundabout>() { GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>(){ {conflicts[0],ConflictResolution.OnCarFirst} }) }; case 2: return new List<IntelligentRoundabout>() { GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>(){ {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.OnCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>(){ {conflicts[0],ConflictResolution.OnCarFirst},{conflicts[1],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>(){ {conflicts[0],ConflictResolution.OnCarFirst},{conflicts[1],ConflictResolution.OnCarFirst} }) }; case 3: return new List<IntelligentRoundabout>() { GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.WaitingCarFirst},{conflicts[2],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.WaitingCarFirst},{conflicts[2],ConflictResolution.OnCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.OnCarFirst},{conflicts[2],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.OnCarFirst},{conflicts[2],ConflictResolution.OnCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.OnCarFirst},{conflicts[1],ConflictResolution.WaitingCarFirst},{conflicts[2],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.OnCarFirst },{conflicts[1],ConflictResolution.WaitingCarFirst},{conflicts[2],ConflictResolution.OnCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.OnCarFirst },{conflicts[1],ConflictResolution.OnCarFirst},{conflicts[2],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.OnCarFirst },{conflicts[1],ConflictResolution.OnCarFirst},{conflicts[2],ConflictResolution.OnCarFirst} }), }; case 4: return new List<IntelligentRoundabout>() { GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.WaitingCarFirst},{conflicts[2],ConflictResolution.WaitingCarFirst},{conflicts[3],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.WaitingCarFirst},{conflicts[2],ConflictResolution.WaitingCarFirst},{conflicts[3],ConflictResolution.OnCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.WaitingCarFirst},{conflicts[2],ConflictResolution.OnCarFirst},{conflicts[3],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.WaitingCarFirst},{conflicts[2],ConflictResolution.OnCarFirst},{conflicts[3],ConflictResolution.OnCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.OnCarFirst},{conflicts[2],ConflictResolution.WaitingCarFirst},{conflicts[3],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.OnCarFirst },{conflicts[2],ConflictResolution.WaitingCarFirst},{conflicts[3],ConflictResolution.OnCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.OnCarFirst },{conflicts[2],ConflictResolution.OnCarFirst},{conflicts[3],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.WaitingCarFirst},{conflicts[1],ConflictResolution.OnCarFirst },{conflicts[2],ConflictResolution.OnCarFirst},{conflicts[3],ConflictResolution.OnCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.OnCarFirst},{conflicts[1],ConflictResolution.WaitingCarFirst},{conflicts[2],ConflictResolution.WaitingCarFirst},{conflicts[3],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.OnCarFirst },{conflicts[1],ConflictResolution.WaitingCarFirst},{conflicts[2],ConflictResolution.WaitingCarFirst},{conflicts[3],ConflictResolution.OnCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.OnCarFirst },{conflicts[1],ConflictResolution.WaitingCarFirst},{conflicts[2],ConflictResolution.OnCarFirst},{conflicts[3],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.OnCarFirst },{conflicts[1],ConflictResolution.WaitingCarFirst},{conflicts[2],ConflictResolution.OnCarFirst},{conflicts[3],ConflictResolution.OnCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.OnCarFirst },{conflicts[1],ConflictResolution.OnCarFirst},{conflicts[2],ConflictResolution.WaitingCarFirst},{conflicts[3],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.OnCarFirst },{conflicts[1],ConflictResolution.OnCarFirst },{conflicts[2],ConflictResolution.WaitingCarFirst},{conflicts[3],ConflictResolution.OnCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.OnCarFirst },{conflicts[1],ConflictResolution.OnCarFirst },{conflicts[2],ConflictResolution.OnCarFirst},{conflicts[3],ConflictResolution.WaitingCarFirst} }), GetStateWithParams(new Dictionary<int, ConflictResolution>() { {conflicts[0],ConflictResolution.OnCarFirst },{conflicts[1],ConflictResolution.OnCarFirst },{conflicts[2],ConflictResolution.OnCarFirst},{conflicts[3],ConflictResolution.OnCarFirst} }), }; default: throw new Exception("Error getting possible solutions: invalid number of conflict points;"); } }
/// <summary> /// Uses median. The lower the better. /// </summary> /// <param name="roundabout"></param> /// <returns></returns> public int WaitTimeMetric(Roundabout roundabout) { var allCars = GetAllCarsOnRoundabout(); if (allCars.Count == 0) { return(0); } var ordered = allCars.OrderBy(e => e.TimeWaiting); var median = ordered.ToArray()[ordered.Count() / 2]; return(median.TimeWaiting); }
private void UpdaterEventHandler(object myObject, EventArgs myEventArgs) { (_roundabout as ConventionalRoundabout)?.IterateSimaultion(); if (_roundabout is IntelligentRoundabout) _roundabout = ((IntelligentRoundabout)_roundabout).GetBestNextOptionMain(); pictureBox3.Invalidate(); CurrTimeLabel.Text = $"Time : {Roundabout.MainCurrTime} sec"; CheckSimulationFinished(); }
private void StartButton_Click(object sender, EventArgs e) { Roundabout.SimulationDuration = (int)SimulationDurationSelector.Value; List<TrafficPattern> patterns = new List<TrafficPattern>(); //Custom car flows //NORTH if (CheckBoxNorth.Checked) patterns.Add(new TrafficPattern(EntryPosition.North, CarPerMinN.IntVal(), ToNFromN.IntVal(), ToEFromN.IntVal(), ToSFromN.IntVal(), ToWFromN.IntVal())); else patterns.Add(new TrafficPattern(EntryPosition.North)); //WEST if (CheckBoxWest.Checked) patterns.Add(new TrafficPattern(EntryPosition.West, CarPerMinW.IntVal(), ToNFromW.IntVal(), ToEFromW.IntVal(), ToSFromW.IntVal(), ToWFromW.IntVal())); else patterns.Add(new TrafficPattern(EntryPosition.West)); //SOUTH if (CheckBoxSouth.Checked) patterns.Add(new TrafficPattern(EntryPosition.South, CarPerMinS.IntVal(), ToNFromS.IntVal(), ToEFromS.IntVal(), ToSFromS.IntVal(), ToWFromS.IntVal())); else patterns.Add(new TrafficPattern(EntryPosition.South)); //SOUTH if (CheckBoxEast.Checked) patterns.Add(new TrafficPattern(EntryPosition.East, CarPerMinE.IntVal(), ToNFromE.IntVal(), ToEFromE.IntVal(), ToSFromE.IntVal(), ToWFromE.IntVal())); else patterns.Add(new TrafficPattern(EntryPosition.East)); //Custom car flows end LaneGroup1.Enabled = false; LaneGroup2.Enabled = false; LaneGroup3.Enabled = false; LaneGroup4.Enabled = false; Roundabout.SimulationDuration = SimulationDurationSelector.IntVal(); SimulationDurationSelector.Enabled = false; //Init roundabout object if (ConventialRadio.Checked) { _roundabout = new ConventionalRoundabout(); _roundabout.Init(patterns); } else { _roundabout = new IntelligentRoundabout(); _roundabout.Init(patterns); } ConventialRadio.Enabled = false; IntelligentRadio.Enabled = false; ResumeButton.Enabled = true; PauseButton.Enabled = false; ManualIterButton.Enabled = true; }
/// <summary> /// Uses median. The lower the better. /// </summary> /// <param name="roundabout"></param> /// <returns></returns> public int WaitTimeMetric(Roundabout roundabout) { var allCars = GetAllCarsOnRoundabout(); if (allCars.Count == 0) return 0; var ordered = allCars.OrderBy(e => e.TimeWaiting); var median = ordered.ToArray()[ordered.Count() / 2]; return median.TimeWaiting; }
public List <IntelligentRoundabout> GetPossibleSolutionsForNextIter(Roundabout roundaboutState) { var conflicts = FindConflictPoints(); switch (conflicts.Count) { case 0: return(new List <IntelligentRoundabout>() { GetStateWithParams(new Dictionary <int, ConflictResolution>()) }); case 1: return(new List <IntelligentRoundabout>() { GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst } }) }); case 2: return(new List <IntelligentRoundabout>() { GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst } }) }); case 3: return(new List <IntelligentRoundabout>() { GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst }, { conflicts[2], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst }, { conflicts[2], ConflictResolution.OnCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst }, { conflicts[2], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst }, { conflicts[2], ConflictResolution.OnCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst }, { conflicts[2], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst }, { conflicts[2], ConflictResolution.OnCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst }, { conflicts[2], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst }, { conflicts[2], ConflictResolution.OnCarFirst } }), }); case 4: return(new List <IntelligentRoundabout>() { GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst }, { conflicts[2], ConflictResolution.WaitingCarFirst }, { conflicts[3], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst }, { conflicts[2], ConflictResolution.WaitingCarFirst }, { conflicts[3], ConflictResolution.OnCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst }, { conflicts[2], ConflictResolution.OnCarFirst }, { conflicts[3], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst }, { conflicts[2], ConflictResolution.OnCarFirst }, { conflicts[3], ConflictResolution.OnCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst }, { conflicts[2], ConflictResolution.WaitingCarFirst }, { conflicts[3], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst }, { conflicts[2], ConflictResolution.WaitingCarFirst }, { conflicts[3], ConflictResolution.OnCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst }, { conflicts[2], ConflictResolution.OnCarFirst }, { conflicts[3], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.WaitingCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst }, { conflicts[2], ConflictResolution.OnCarFirst }, { conflicts[3], ConflictResolution.OnCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst }, { conflicts[2], ConflictResolution.WaitingCarFirst }, { conflicts[3], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst }, { conflicts[2], ConflictResolution.WaitingCarFirst }, { conflicts[3], ConflictResolution.OnCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst }, { conflicts[2], ConflictResolution.OnCarFirst }, { conflicts[3], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.WaitingCarFirst }, { conflicts[2], ConflictResolution.OnCarFirst }, { conflicts[3], ConflictResolution.OnCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst }, { conflicts[2], ConflictResolution.WaitingCarFirst }, { conflicts[3], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst }, { conflicts[2], ConflictResolution.WaitingCarFirst }, { conflicts[3], ConflictResolution.OnCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst }, { conflicts[2], ConflictResolution.OnCarFirst }, { conflicts[3], ConflictResolution.WaitingCarFirst } }), GetStateWithParams(new Dictionary <int, ConflictResolution>() { { conflicts[0], ConflictResolution.OnCarFirst }, { conflicts[1], ConflictResolution.OnCarFirst }, { conflicts[2], ConflictResolution.OnCarFirst }, { conflicts[3], ConflictResolution.OnCarFirst } }), }); default: throw new Exception("Error getting possible solutions: invalid number of conflict points;"); } }