Skip to content

Commit b55896e

Browse files
committed
Added Dirty Flag TSP example to readme
1 parent 668877f commit b55896e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ This pattern is useful if something has changed in your game, and if so you have
422422

423423
* If you ever done some editor scripting in Unity, you know that you can use SetDirty() to mark an object as dirty or you can even mark the entire scene as dirty. Now Unity will understand that you have changed something and those changes should be saved when you save your scene.
424424

425-
* Unity is using it in the physics system. A RigidBody doesn't have to be updated unless a force is applied to it. If the RigidBody is sleeping (not moving), a Dirty Flag is used so the physics system can ignore it.
425+
* Unity is using it in the physics system. A RigidBody doesn't have to be updated unless a force is applied to it. If the RigidBody is sleeping (not moving), a Dirty Flag is used so the physics system can ignore it.
426+
427+
* I used this pattern when experimenting with Genetic Algorithms (GA) and the Traveling Salesman Problem (TSP) where you find the shortest path between multiple cities. The GA generates multiple solutions, like 100, to the TSP and then each iteration you evolve 100 better solutions by calculating a cost function, which is the distance between all cities. You can use "tournament selection" to find good solutions from the previous iteration to the next, which is basically picking 3 solutions and returns the solution with the shortest distance between all cities. I realized I didn't have to calculate the cost fuction 100 times each iteration because it's a costly operation. To optimize I only calculate the cost function of the cities being picked by the tournament selection. I kept track of which solution has had its cost fuction calculated by using a boolean which is set to false each iteration and then to true if the cost function had been run.
426428

427429

428430

@@ -521,7 +523,7 @@ If you are creating several different factories, then they should inherit from s
521523

522524
**Related patterns**
523525

524-
* [Prototype](#4-prototype). The Prototype pattern is generally used if you want to make a copy an existing object, while the Factory pattern is generating new objects. But some argue you can put the Prototype pattern inside of the Factory pattern.
526+
* [Prototype](#4-prototype). The Prototype pattern is generally used if you want to make a copy of an existing object, while the Factory pattern is generating new objects. But some argue you can put the Prototype pattern inside of the Factory pattern.
525527

526528

527529

0 commit comments

Comments
 (0)