On Simple Rules

My task of the week was to setup a simple car driving world and make cars move in it. My initial setup was a closed path where one car was moving indefinitely. My NetLogo world lokked like this:

netlogo1

In there, the car should travel the green path and never touch a black path. We can state simple rules to move a single car in this circuit:

  • If path ahead is green then go forward
  • If path ahead is not green and right path is green then turn right
  • If path ahead is not green and left path is green then turn left

The rules are checked on that order, once a rule holds the next rules are not checked. And given that the car can only goes forward and never backwards, we have exhausted all the possibilities. Keep in mind that our current rules favor right turns over left turns, if we want a more partial turning we could throw a coin to decide which direction to turn.

A little more complex is the world with two lanes where a car in a given lane must keep its right:

netlogo2

If we try to use the same previous rules, the inner car will not keep its right, invade the outer lane and just follow the outer car. Because it will have a green path ahead after it gets to the first corner. We need to add more rules to our set:

  • If path ahead is green and right path is green then turn right.
  • If path ahead is green and right path is not green then go forward.
  • If path ahead is not green and right path is green then turn right.
  • If path ahead is not green and right path is not green then turn left.

With these new rules the outer car still follows its right, and the inner car does not invade the outer lane. However, when the inner car gets to the first corner it gets stuck. Why? Because of our first rule and the fact that all the paths round the car are green, so for each turn it will be in the same configuration and will get stuck.

To solve this problem the car should remember if in the last action it went forward or turned: if it went forward then it will turn, and otherwise will forward. The new rules with memory are then:

  • If path ahead is green and right path is green and last action was turn right then go forward.
  • If path ahead is green and right path is green and last action was go forward then turn right.
  • If path ahead is green and right path is not green then go forward.
  • If path ahead is not green and right path is green then turn right.
  • If path ahead is not green and right path is not green then turn left.

And now both cars will keep always their right. What will happen if we have a grid of lanes? Such as in the picture:

netlogo3

Our new rules with memory fails again. The rules should be updated with any new environment, or we could try to implement general rules that work in any environment. Both ways will have their own set of problems and complexities, but they will be studied in a future post.

On Simple Rules
Share this