forked from cyb0124/FissionOpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptFission.h
63 lines (57 loc) · 1.64 KB
/
OptFission.h
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
#ifndef _OPT_FISSION_H_
#define _OPT_FISSION_H_
#include <random>
#include <memory>
#include "Fission.h"
namespace Fission {
struct Sample {
int limit[Air];
xt::xtensor<int, 3> state;
Evaluation value;
};
enum {
StageTrain = -2,
StageInfer
};
constexpr int interactiveMin(1024), interactiveScale(327680), interactiveNet(16), nLossHistory(256);
class Net;
class Opt {
friend Net;
const Settings &settings;
Evaluator evaluator;
Coords allowedCoords;
std::vector<int> allowedTiles;
int nEpisode, nStage, nIteration;
int nConverge, maxConverge;
double infeasibilityPenalty;
double parentFitness;
Sample parent, best;
std::array<Sample, 4> children;
std::mt19937 rng;
std::unique_ptr<Net> net;
bool inferenceFailed;
bool bestChanged;
int redrawNagle;
std::vector<double> lossHistory;
bool lossChanged;
void restart();
bool feasible(const Evaluation &x);
double rawFitness(const Evaluation &x);
double currentFitness(const Sample &x);
int getNSym(int x, int y, int z);
void setTileWithSym(Sample &sample, int x, int y, int z, int tile);
void mutateAndEvaluate(Sample &sample, int x, int y, int z);
public:
Opt(const Settings &settings, bool useNet);
void step();
void stepInteractive();
bool needsRedrawBest();
bool needsReplotLoss();
const std::vector<double> &getLossHistory() const { return lossHistory; }
const Sample &getBest() const { return best; }
int getNEpisode() const { return nEpisode; }
int getNStage() const { return nStage; }
int getNIteration() const { return nIteration; }
};
}
#endif