Question: #include trafficSimulator.h / / optional TODO: Put your new function declarations here int max ( int a , int b ) ; / *

#include "trafficSimulator.h"
//optional TODO: Put your new function declarations here
int max( int a, int b );
/* printNames
* input: none
* output: none
*
* Prints names of the students who worked on this solution
* REMINDER: You may only work with one other cs2124 student
*/
void printNames()
{
/* TODO : Fill in you and your partner's names (or N/A if you worked individually)*/
printf("
This solution was completed by:
");
printf("
");
printf("
");
}
/* createTrafficData
* input: char* filename of file to read
* output: TrafficData* which stores the data of this road network
*
* Create a new TrafficData variable and read in the traffic data from the file whose name is stored in char* filename
*/
TrafficData* createTrafficData( char* filename )
{
/* open the file */
FILE *pFile = fopen( filename, "r");
if( pFile==NULL )
{
printf("ERROR - the file \"%s\" was not found!
", filename);
exit(-1);
}
/* TODO: read in all the data in pFile */
/* HINT: use fscanf( pFile, "%d", & ) to read an int from pFile */
/* HINTs:
* Each road can be stored in a `RoadData` struct (see `road.h`).
*
* You'll want to store all of these `RoadData` structs in a single array. This is important to track the order that
* roads were added to your graph. These are also the order they are processed in each time step. You can store this
* in the arrayOfRoads variable in your TrafficData struct.
*
* You'll add edges to a graph to represent each road using `setEdge`(see `graph.c`). The vertices of the graph
* represent intersections. The graph will do the work of finding shortest paths (see `getNextOnShortestPath` in graph.c
* and the longest shortest path problem on Canvas).
*
* It will also help to add your `RoadData` structs to your graph using `setEdgeData`(see `graph.c`). You can then
* retrieve that `RoadData` struct by calling `getEdgeData`. This will be helpful for finding roads when cars pass
* through intersections.
*
* Each event will be stored in an Event struct (see `event.h`).
*
* It's recommended to store all of the `Event` structs in a single priority queue (using time step as the priority). This
* allows you to quickly find the next event to execute by time step (see `enqueueByPriority`,`getFrontPriority`, and
*`dequeuePQ`).
*
* Each car is stored in a Car struct (see `car.h`).
*/
/* close file */
fclose( pFile );
return NULL; /* TODO: Replace this with your TrafficData pointer */
}
/* trafficSimulator
* input: char* name of file to read
* output: N/A
*
* Simulate the road network in the given TrafficData variable
*/
void trafficSimulator( TrafficData* pTrafficData )
{
/* TODO: complete this function */
/* Loop until all events processed and either all cars reached destination */
/* You can also assume all test data will finish in 1000 steps */
/* This fact can be used to help you avoid infinite loops while completing the project */
/* Print the current step number */
/* Update the state of every traffic light */
/* Loop on events associated with this time step */
/* If ADD_CAR_EVENT, use mergeQueues from queue.h to add the queue of cars to the queue of the road associated with the event */
/* If ROAD_ACCIDENT_EVENT, add one to the numAccidents of the road associated with the event */
/* If ROAD_RESOLVED_EVENT, subtract one from the numAccidents of the road associated with the event */
/* For each road, try to move waiting cars onto the end of that road if possible (remember to check that numAccidents==0 for the road)*/
/* For each road, try to move cars, which haven't already moved, forward one space on every road (remember to check that numAccidents==0 for the road)*/
/* For each road, try to move cars, which haven't already moved, through the next intersection (remember to check that numAccidents==0 for both roads)*/
/* After the loop finishes print the average and max number of steps it took for a car to reach its destination */
}
/* freeTrafficData
* input: TrafficData* pTrafficData
* output: N/A
*
* Free the data in the TrafficData variable
*/
void freeTrafficData( TrafficData* pTrafficData )
{
/* TODO: complete this function */
}
int max( int a, int b )
{
if(a>b)
return a;
return b;
}
#include "trafficSimulator.h " / / optional TODO:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!