- Barriers (2.5)
A simple genetic algorithm was implemented in the example project Barriers.
- Initialization of the first generation with random values
- Evaluation - that is, calculation of a value based on a parameter
- Lottery - based on the ranking. The last one has one chance, the one before last has two, etc.
- Bitwise crossover
- Mutation
Rewrite the program so that the evaluation is carried out on a separate thread for each element of the array. Each iteration of the algorithm is to be synchronized by a barrier(System.Threading.Barrier, SignalAndWait).
Consider whether one barrier is enough?
- Monitors (1)
Add a new project to the solution - Monitors. Let's add a reference to the previous project to use the GAHelper class. The code contained in Program.cs can be partially copied.
Instead of the barrier mechanism, use Monitor that simulates the Barrier. Monitor has two methods to help us, Wait and PulseAll . You should also add a counting counter whether the barrier has already been reached or not.
- Threads in WPF (1.5)
In the sample solution in the WPFThreads project, a simple producer and consumer problem based on BlockingCollection was implemented. After starting the program in the diagnostic window "Output", using Trace.WriteLine, it displays information from the producer and consumers.
The application window shows nothing yet.
The application should be modified in such a way that the producer prints information about adding the item in the left TextRichBox and consumers about geting the item in the right. In addition, in the middle, we should see the status of the collection, how many items are currently in it.
For example like that:
Remember that a thread that is not the creator of a given GUI element cannot change it directly. The mechanisms learned during the lecture should be used (e.g. Dispatcher.Invoke).