-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask.cpp
125 lines (114 loc) · 2.17 KB
/
Task.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "Task.hpp"
#include "Agent.hpp"
#include "Pluribus.hpp"
#include "Processor.hpp"
#include "Trainer.hpp"
Task::Task() {
Init();
}
Task::~Task() {
}
void Task::Init() {
mType = TASK_TYPE_NONE;
mTaskId = 0;
mFactor = 1.0;
mAgent = nullptr;
mPluribus = nullptr;
mProcessor = nullptr;
mTrainer = nullptr;
}
void Task::Process() {
switch (mType) {
case TASK_TYPE_TRAIN:
train();
break;
case TASK_TYPE_DISCOUNT:
discount();
break;
case TASK_TYPE_STRATEGY:
strategy();
break;
case TASK_TYPE_RESEARCH:
research();
break;
case TASK_TYPE_LOAD_MODEL:
modelLoad();
break;
case TASK_TYPE_SAVE_MODEL:
modelSave();
break;
default:
LOGF_ERROR("unknown type: %d", mType);
break;
}
}
void Task::train() {
if (nullptr != mPluribus) {
mPluribus->trainConsume(mTaskId);
} else {
LOG_ERROR("@Task: mPluribus is nullptr!");
}
//
if (nullptr != mTrainer) {
mTrainer->incrTaskProcessed();
} else {
LOG_ERROR("@Task: mTrainer is nullptr!");
}
}
void Task::discount() {
if (nullptr != mAgent) {
mAgent->Discount(mFactor);
} else {
LOG_ERROR("@Task: mAgent is nullptr!");
}
//
if (nullptr != mProcessor) {
mProcessor->incrDiscountProcessed();
}
}
void Task::strategy() {
if (nullptr != mAgent) {
mAgent->UpdateStrategy();
} else {
LOG_ERROR("@Task: mAgent is nullptr!");
}
//
if (nullptr != mProcessor) {
mProcessor->incrStrategyProcessed();
}
}
void Task::research() {
if (nullptr != mPluribus) {
mPluribus->searchConsume(mTaskId);
} else {
LOG_ERROR("@Task: mPluribus is nullptr!");
}
//
if (nullptr != mProcessor) {
mProcessor->incrTaskProcessed();
} else {
LOG_ERROR("@Task: mProcessor is nullptr");
}
}
void Task::modelLoad() {
if (nullptr != mAgent) {
mAgent->Load();
} else {
LOG_ERROR("@Task: mAgent is nullptr!");
}
//
if (nullptr != mTrainer) {
mTrainer->incrAgentLoadedNum();
}
}
void Task::modelSave() {
if (nullptr != mAgent) {
mAgent->Save(mSuffix);
} else {
LOG_ERROR("@Task: mAgent is nullptr!");
}
//
if (nullptr != mTrainer) {
mTrainer->incrAgentSavedNum();
}
}