Project1 course outcome for ENGR151 in UM-SJTU JI. Incoming students of JI should not refer to this repo when completing the project. Any misconduct detected will be considered as violation to honor code, and will receive heavy punishment. The owner of this repo will not be held responsible for other people's mistake
Name: Haoyang Wu Email: [email protected]
This project simulates the traffic situation of a crossroad.
- The total number of cars crossing the crossroad, and the program will randomly assign the number of cars on each side.
- The width of the road
- The probability of a car not stopping at a red light
- Lasting time for green lights
- Lasting time for yellow lights
- Lasting time for red lights
- Speed for the cars in four directions
OK.
- The number of cars on each road isn't exactly random because the randi function itself is a pseudorandom.
- The light1 is the two lights on the left lower and right upper corners that control the cars from the left and right
- The light2 is the two lights on the left upper and right lower corners that control the cars from the up and below
- Referred to the codes provided in the "Plot Circle" part of the "Plot function" when writing the function: "trafficlightinit"
- The initial traffic light color should be green for the cars moving from left and right, and red for the cars moving from up and down.
- The cars move one unit per second, and the width of the road is measured by units(e.g. if the road is 4 units wide, it means it takes the car 4 seconds to cross the road).
- The cars are set to take up half of a lane, changing the width of the road won't change this.
- The cars are set to be one unit long, changing the width of the road might change the shape of the cars.
- For now, the program uses the flag variable to execute and quit the loop, thus the program will run for 40 seconds, but in a later version flag will be deleted and the criteria to exit the loop will be changed to cars crash.
- Each car that arrives at the starting line when the light is red has to decide if it should stop at the red.
- The permutation is not fully random, it can only generate a certain subset with n(number of cars) output elements of the permutation of the randomly selected input elements.
- The speed of the cars has only three levels, entering number beside 1,2,3 would not be valid and the program will ask you to enter the speed again
- The cars move ten times per second in order to make the animation look more consistent and be better at detecting car crashes.
- The function generateperm is the function I initially used to generate car plates, but it is not random enough as it can only generate multiple permutations of a given set of elements(e.g. the last five digits will be like ABC12 ABC21 AB1C2...). So I changed the algorithm and wrote the generatecarplates function. However, I still uploaded the original function with the project because I think it is a very powerful function that can generate the permutations of a certain set of elements as much as you want with one function.