// Start is called before the first frame update void Start() { b = FindObjectOfType <TrafficBoard>(); WE_Semaphore = new Node[20]; NS_Semaphore = new Node[20]; SetSemaphores(); time = 300; currentTimer = time; currTraffStatus = "low"; currTimerType = "slow"; set = new float[3]; cars = 0; }
// Start is called before the first frame update void Start() { t = FindObjectOfType <TrafficBoard>(); convergence = false; while (convergence == false) { convSum = 0; Node[,] newState = new Node[100, 100]; for (int x = 0; x < 99; x++) { for (int y = 0; y < 99; y++) { currentNode = t.grid[x, y]; //newState[x, y] = new Node(currentNode.isWall,currentNode.posX,currentNode.posY); newState[x, y] = MDPSolver(x, y); } } Debug.Log("Andres"); for (int x = 0; x < 99; x++) { for (int y = 0; y < 99; y++) { convSum += t.grid[x, y].reward - newState[x, y].reward; } } if (convSum == 0f || laps == 1) { Debug.Log(laps); convergence = true; } else { laps++; for (int x = 0; x < 99; x++) { for (int y = 0; y < 99; y++) { t.grid[x, y] = newState[x, y]; } } } } }
/** * Close form add save data * */ private void close_Click(object sender, EventArgs e) { for (int rows = 0; rows < signs.Rows.Count - 1; rows++) { TrafficBoard temp = new TrafficBoard(); Point1 pt1 = new Point1(); pt1.name = signs.Rows[rows].Cells[0].Value.ToString(); temp.point1 = pt1; Point2 pt2 = new Point2(); pt2.name = signs.Rows[rows].Cells[1].Value.ToString(); temp.point2 = pt2; temp.boardNumber = Int32.Parse(signs.Rows[rows].Cells[2].Value.ToString()); boards.Add(temp); } this.Close(); }
/** * Save Street Data * */ private void save_Click(object sender, EventArgs e) { /////////////////////////Add Street in database///////////////////////////// Street st = new Street(); st.streetName = sname.Text; st.direction = Int32.Parse(sdir.Text); db.streets.Add(st); db.SaveChanges(); ////////////////////////Add points in database/////////////////////// List <Point1> listOfPoint1 = new List <Point1>(); List <Point2> listOfPoint2 = new List <Point2>(); for (int rows = 0; rows < AddPointsProgressForm.AllPoints.Count - 1; rows++) { AddPointsProgressForm.AllPoints[rows].street = st; db.points1.Add(AddPointsProgressForm.AllPoints[rows]); listOfPoint1.Add(AddPointsProgressForm.AllPoints[rows]); db.SaveChanges(); } for (int rows = 1; rows < AddPointsProgressForm.AllPoints.Count; rows++) { AddPointsProgressForm.AllPoints[rows].street = st; Point2 point2 = new Point2(); point2.id = AddPointsProgressForm.AllPoints[rows].Getid(); point2.lat = AddPointsProgressForm.AllPoints[rows].lat; point2.lon = AddPointsProgressForm.AllPoints[rows].lon; point2.name = AddPointsProgressForm.AllPoints[rows].name; point2.elev = AddPointsProgressForm.AllPoints[rows].elev; db.points2.Add(point2); listOfPoint2.Add(point2); db.SaveChanges(); } ////////////////////////Add Intersections in database/////////////////////// Intersection tempForIntersection = new Intersection(); for (int rows = 0; rows < intersections.Rows.Count - 1; rows++) { tempForIntersection.numberOfIntersection = rows + 1; tempForIntersection.pointIndex = Int32.Parse(intersections.Rows[rows].Cells[0].Value.ToString()); tempForIntersection.case1 = Int32.Parse(intersections.Rows[rows].Cells[1].Value.ToString()); tempForIntersection.case2 = Int32.Parse(intersections.Rows[rows].Cells[2].Value.ToString()); tempForIntersection.case3 = Int32.Parse(intersections.Rows[rows].Cells[3].Value.ToString()); tempForIntersection.delayTime1 = Int32.Parse(intersections.Rows[rows].Cells[4].Value.ToString()); tempForIntersection.delayTime2 = Int32.Parse(intersections.Rows[rows].Cells[5].Value.ToString()); tempForIntersection.delayTime3 = Int32.Parse(intersections.Rows[rows].Cells[6].Value.ToString()); tempForIntersection.street = st; db.intersctions.Add(tempForIntersection); db.SaveChanges(); } ////////////////////////Add Segments in database/////////////////////// Segment tempSegment = new Segment(); int first_intersection = Int32.Parse(intersections.Rows[0].Cells[0].Value.ToString()); int last_intersection = Int32.Parse(intersections.Rows[intersections.Rows.Count - 2].Cells[0].Value.ToString()); tempSegment.firstIntersection = first_intersection; tempSegment.secondIntersection = Int32.Parse(intersections.Rows[1].Cells[0].Value.ToString()); for (int point = first_intersection, intersect = 1; ; point++) //from first intersection to last intersection in the same street { if (point == tempSegment.secondIntersection) { tempSegment.firstIntersection = tempSegment.secondIntersection; if (tempSegment.firstIntersection == last_intersection) { db.SaveChanges(); break; } tempSegment.secondIntersection = Int32.Parse(intersections.Rows[++intersect].Cells[0].Value.ToString()); } tempSegment.street = st; tempSegment.point1 = listOfPoint1[point - 1]; tempSegment.point2 = listOfPoint2[point - 1]; db.segment.Add(tempSegment); db.SaveChanges(); } ////////////////////////Add TrafficBoard in database/////////////////////// TrafficBoard tempTrafficBoard = new TrafficBoard(); for (int row = 0; row < AddSignsForm.boards.Count; row++) { tempTrafficBoard.street = st; tempTrafficBoard.boardNumber = AddSignsForm.boards[row].boardNumber; tempTrafficBoard.point1 = listOfPoint1[Int32.Parse(AddSignsForm.boards[row].point1.name) - 1]; tempTrafficBoard.point2 = listOfPoint2[Int32.Parse(AddSignsForm.boards[row].point2.name) - 1]; db.trafficBoard.Add(tempTrafficBoard); db.SaveChanges(); } db.SaveChanges(); AddSignsForm.boards.RemoveRange(0, AddSignsForm.boards.Count); listOfPoint1.RemoveRange(0, listOfPoint1.Count); listOfPoint2.RemoveRange(0, listOfPoint2.Count); this.Close(); }
void PrepareLists() { b = FindObjectOfType <TrafficBoard>(); Open = new List <Node>(); Closed = new List <Node>(); }