Skip to content

Commit

Permalink
Add data squashing technique
Browse files Browse the repository at this point in the history
  • Loading branch information
firefly-cpp committed Mar 15, 2022
1 parent 4c84592 commit 0f19337
Show file tree
Hide file tree
Showing 9 changed files with 563 additions and 8 deletions.
11 changes: 11 additions & 0 deletions bin/arm.set
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ Period = 1
%Intervals = 5
}

% Squashing algorithm selection = {NONE, CAUCHY, EUCLID, ...}
%Squash = EUCLID
%CAUCHY_PARAM
%{
%THRESHOLD = 0.99
%}
%EUCLID_PARAM
%{
%THRESHOLD = 0.9
%}

% Algoritem selection = {NONE, DE, PSO, ...}
Algorithm = DE
% DE parameters
Expand Down
6 changes: 3 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ ifeq ($(DEBUG), 1)
CXXFLAGS := $(CXXFLAGS) -O0 -g3 -Wall -fmessage-length=0
endif

SRCS = ./sources/Archive.cpp ./sources/Attribute.cpp ./sources/DESolver.cpp ./sources/Evaluate.cpp ./sources/Feature.cpp ./sources/Problem.cpp ./sources/Rule.cpp ./sources/Setup.cpp ./sources/uARMSolver.cpp
SRCS = ./sources/Archive.cpp ./sources/Attribute.cpp ./sources/DESolver.cpp ./sources/Evaluate.cpp ./sources/Feature.cpp ./sources/Problem.cpp ./sources/Rule.cpp ./sources/Setup.cpp ./sources/Squash.cpp ./sources/uARMSolver.cpp

DEPS = ./Archive.d ./Attribute.d ./DESolver.d ./Evaluate.d ./Feature.d ./Problem.d ./Rule.d ./Setup.d ./uARMSolver.d
DEPS = ./Archive.d ./Attribute.d ./DESolver.d ./Evaluate.d ./Feature.d ./Problem.d ./Rule.d ./Setup.d ./Squash.d ./uARMSolver.d

OBJS = ./Archive.o ./Attribute.o ./DESolver.o ./Evaluate.o ./Feature.o ./Problem.o ./Rule.o ./Setup.o ./uARMSolver.o
OBJS = ./Archive.o ./Attribute.o ./DESolver.o ./Evaluate.o ./Feature.o ./Problem.o ./Rule.o ./Setup.o ./Squash.o ./uARMSolver.o

all: bin/uARMSolver

Expand Down
6 changes: 3 additions & 3 deletions sources/DESolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ DESolver::DESolver(int dim,int popSize, Problem problem) :
{
prob = problem;
nDim = eval.encode(D, prob);

cout << "DESolver: dim= " << nDim << ", nPop= " << nPop << endl;
for(int i=0;i<nDim;i++) {
trialSolution.push_back(0.0);
bestSolution.push_back(0.0);
}
for(int i=0;i<nPop;i++) {
popEnergy.push_back(0-0);
popEnergy.push_back(0.0);
vector<double> row;
for(int j=0;j<nDim;j++) {
row.push_back(0.0);
Expand Down Expand Up @@ -69,7 +69,7 @@ void DESolver::Setup(int deStrategy, double diffScale, double crossoverProb)
strategy = deStrategy;
scale = diffScale;
probability = crossoverProb;
cout << "Initialisation of population..." << endl;
for (i=0; i < nPop; i++)
{
for (int j=0; j < nDim; j++)
Expand Down
3 changes: 3 additions & 0 deletions sources/Problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ bool Problem::init_tdbase(Setup setup, string tfile_name)
auto_parsing = true;

if (in.is_open()) {
//cout << "File: " << tfile_name << endl;
//int li = 1;
while (getline(in, line)) {
//cout << "Line " << li++ << ": \'" << line << "\'" << endl;
vector<string> tokens;
token_line(line, tokens, ',');
if (auto_parsing) {
Expand Down
101 changes: 101 additions & 0 deletions sources/Setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ bool Setup::read()
} else if (tokens[0].compare("Visualisation") == 0) {// visualizationblock
block = 3;
visual = vis_to_int(tokens[2]);
} else if (tokens[0].compare("Squash") == 0) {// squashing
block = 4;
squash = sq_to_int(tokens[2]);
} else if (tokens[0][0] == '%') { // comment line - ignore
continue;
} else if (tokens[0][0] == '{') { // start of block
Expand All @@ -60,6 +63,9 @@ bool Setup::read()
case 3: // parsing visualization block
parse_vis_blk(tokens);
break;
case 4: // parsing squashing block
parse_sq_blk(tokens);
break;
}
}

Expand Down Expand Up @@ -102,6 +108,8 @@ void Setup::parse_prob_blk(vector<string>tokens)
{
if(tokens[0].compare("Tdbase_name") == 0) {
tdbase_name = tokens[2];
} else if(tokens[0].compare("SqDbase_name") == 0) {
sq_dbase_name = tokens[2];
} else if(tokens[0].compare("Rule_name") == 0) {
rule_name = tokens[2];
} else if(tokens[0].compare("Out_name") == 0) {
Expand Down Expand Up @@ -231,6 +239,72 @@ int Setup::vis_to_int(string vis)
return n_vis;
}

/**
* Parse the kind of squashing algorithm for solving ARM.
*
* @param the vector of parsed tokens.
* @return no return code.
*/
void Setup::parse_sq_blk(vector<string>tokens)
{
switch(squash) {
case SQUASH_CAUCHY:
parse_sq_cauchy(tokens);
break;
case SQUASH_EUCLID:
parse_sq_euclid(tokens);
break;
}
}

/**
* Parse the parameter setting of the Cauchy squashing algorithm for solving ARM.
*
* @param the vector of parsed tokens.
* @return no return code.
*/
void Setup::parse_sq_cauchy(vector<string>tokens)
{
if (tokens[0].compare("CAUCHY_PARAM") == 0) {
cout << "CAUCHY_PARAM started..." << endl;
} else if (tokens[0].compare("THRESHOLD") == 0) {
sq_param.sq.Thresh = stof(tokens[2]);
}
}

/**
* Parse the parameter setting of the Euclidian squashing algorithm for solving ARM.
*
* @param the vector of parsed tokens.
* @return no return code.
*/
void Setup::parse_sq_euclid(vector<string>tokens)
{
if (tokens[0].compare("EUCLID_PARAM") == 0) {
cout << "EUCLID_PARAM started..." << endl;
} else if (tokens[0].compare("THRESHOLD") == 0) {
sq_param.sq.Thresh = stof(tokens[2]);
}
}

/**
* Map the squashing method from string.
*
* @param the string.
* @return integer return code identifying the visualization method.
*/
int Setup::sq_to_int(string sq)
{
int n_sq = SQUASH_NONE;

if(sq.compare("CAUCHY") == 0) {
n_sq = SQUASH_CAUCHY;
} else if(sq.compare("EUCLID") == 0) {
n_sq = SQUASH_EUCLID;
}
return n_sq;
}

/**
* Print out all three parameter parts determining a behavior of the solver.
*
Expand All @@ -242,6 +316,7 @@ void Setup::print_param()
print_prob_blk();
print_alg_blk();
print_vis_blk();
print_sq_blk();
}

/**
Expand All @@ -255,6 +330,7 @@ void Setup::print_prob_blk()
cout << "Problem block setup: " << endl;
cout << "---------------------" << endl;
cout << "Tdbase_name= " << tdbase_name << endl;
cout << "SqDbase_name= " << sq_dbase_name << endl;
cout << "Rule_name= " << rule_name << endl;
cout << "Out_name= " << out_name << endl;
cout << "Period= " << period << endl;
Expand Down Expand Up @@ -318,6 +394,31 @@ void Setup::print_vis_blk()
cout << "---------------------" << endl;
}

/**
* Print out the parameter setting of the squashing method.
*
* @param no input parameters.
* @return no return code.
*/
void Setup::print_sq_blk()
{
cout << "Squashing block setup: " << endl;
cout << "---------------------" << endl;

switch(squash) {
case SQUASH_CAUCHY:
cout << "Method= CAUCHY" << endl;
cout << "Threshold= " << sq_param.sq.Thresh << endl;
break;
case SQUASH_EUCLID:
cout << "Method= EUCLID" << endl;
break;
default:
cout << "Method= NONE" << endl;
}
cout << "---------------------" << endl;
}

/**
* Print out the tokens parsed from the input line.
*
Expand Down
25 changes: 25 additions & 0 deletions sources/Setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#define VISUAL_FLOW 1
#define VISUAL_METRO 2

#define SQUASH_NONE 0
#define SQUASH_CAUCHY 1
#define SQUASH_EUCLID 2

using namespace std;

// algorithm's setups
Expand All @@ -34,6 +38,11 @@ using namespace std;
int N;
};

// squashing setups
struct sq_param {
double Thresh;
};

/**
* Definition of setup parameter input file
*
Expand Down Expand Up @@ -61,25 +70,34 @@ class Setup {
void parse_vis_blk(vector<string>tokens);
void parse_vis_flow(vector<string>tokens);
int vis_to_int(string vis);
void parse_sq_blk(vector<string>tokens);
void parse_sq_cauchy(vector<string>tokens);
void parse_sq_euclid(vector<string>tokens);
int sq_to_int(string sq);

void print_tokens(vector<string>tokens);
void print_prob_blk();
void print_alg_blk();
void print_vis_blk();
void print_sq_blk();
void print_param();

// getters
int get_solver() { return solver; }
int get_period() { return period; }
int get_squash() { return squash; }
int get_Np() { return Np; }
int get_FEs() { return FEs; }
int get_RUNs() { return RUNs; }
string get_tdbase_name() { return tdbase_name; }
string get_sq_dbase_name() { return sq_dbase_name; }
string get_rule_name() { return rule_name; }
string get_out_name() { return out_name; }

// setters
void set_solver(int val) { solver = val; }
void set_period(int val) { period = val; }
void set_squash(int val) { squash = val; }
void set_Np(int val) { Np = val; }
void set_FEs(int val) { FEs = val; }
void set_RUNs(int val) { RUNs = val; }
Expand All @@ -91,12 +109,14 @@ class Setup {
int period; ///< number of transaction databases & archives
int solver; ///< algorithm for solving ARM
int visual; ///< visualization method
int squash; ///< squashing method
int Np; ///< population size
int FEs; ///< number of fitness function evaluations
int RUNs; ///< number of independent runs

string arm_set_name; ///< ARM setup file name
string tdbase_name; ///< transaction database
string sq_dbase_name; ///< squashed database
string rule_name; ///< rule database
string out_name; ///< output file name

Expand All @@ -108,6 +128,11 @@ class Setup {
union {
flow_param flow;
} vis_param; ///< visualization parameters

union {
sq_param sq;
} sq_param; ///< squashing parameters

};

#endif /* SETUP_H_ */
Loading

0 comments on commit 0f19337

Please sign in to comment.