Instruction

by Paweł Paduch published 2021/01/21 21:41:00 GMT+2, last modified 2021-01-25T18:10:02+02:00
  1. 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?

  2. 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.

  3. 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. 

    image.png

    The application window shows nothing yet. 
    image.png

    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:

    d71661b1-a54e-4392-920d-9c113ab135c5.png

    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).