aboutsummaryrefslogtreecommitdiff
path: root/oop2w5/Blackboard.h
blob: 30be0bec362811d27cab51bd245bbe70d48c3910 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once

#include <thread>
#include <vector>
#include <mutex>

#include "BlackboardStrategy.h"

using std::thread;
using std::vector;
using std::mutex;

unsigned gert();

class Blackboard {
private:
	thread* _subthreads[6]; // first fork (2 split)
	thread* _subsubthreads[6]; // second fork (3 split)
	BlackboardStrategy* _bbs = nullptr; // BlackboardStrategy instance
	mutex _bbs_lock; // BlackboardStrategy lock (set/getBest functions)
	unsigned _fitness[6]; // fitness return values
	vector<unsigned> _results; // result return values

	unsigned (BlackboardStrategy::* fitnessStrategies[6])() const = {
		&BlackboardStrategy::fitnessStrategy1,
		&BlackboardStrategy::fitnessStrategy2,
		&BlackboardStrategy::fitnessStrategy3,
		&BlackboardStrategy::fitnessStrategy4,
		&BlackboardStrategy::fitnessStrategy5,
		&BlackboardStrategy::fitnessStrategy6,
	};

	unsigned (BlackboardStrategy::* resultStrategies[6])() const = {
		&BlackboardStrategy::resultStrategy1,
		&BlackboardStrategy::resultStrategy2,
		&BlackboardStrategy::resultStrategy3,
		&BlackboardStrategy::resultStrategy4,
		&BlackboardStrategy::resultStrategy5,
		&BlackboardStrategy::resultStrategy6,
	};

public:
	Blackboard();
	virtual ~Blackboard();
	/** @brief start subthreads for strategy[start_index] until strategy[start_index + length] */
	virtual void spawn_subthreads(unsigned start_index, unsigned length);
	virtual void run();
};