-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctionTest.cpp
113 lines (108 loc) · 2.4 KB
/
functionTest.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
/*
* --------------------------------------------------------------
* File: functionTest.cpp
* Project: Code
* Created: Friday, 5th April 2019 1:52:54 pm
* @Author: molin@live.cn
* Last Modified: Friday, 5th April 2019 1:53:02 pm
* Copyright © Rockface 2018 - 2019
* --------------------------------------------------------------
*/
#include "util_random.h"
#include "util.h"
#include <iostream>
#include <vector>
#include <sstream>
#include <cstring>
#include <fstream>
#include <algorithm>
class Example{
public:
int *port;
Example(){
port = new int[10];
}
double risk;
double income;
void assign(double risk, double income){
this->risk = risk;
this->income = income;
}
void echo(){
std::cout<<risk<<"\t"<<income<<std::endl;
}
~Example(){
delete []port;
std::cout<<"Example, de\n";
}
void operator=(Example const &x){
risk = x.risk;
income = x.income;
for(int i = 0; i<10; i++){
port[i] = x.port[i];
}
}
};
class moead_Example: public Example{
public:
moead_Example(){
}
~moead_Example(){
std::cout<<"moead_Example, de\n";
}
};
bool dom(Example&x, Example&y){
if((x.risk<y.risk)and(x.income>y.income)){
return true;
}
return false;
}
void testDom(){
fstream inFile("Output/MOEA-D/Test4/initEP.txt", ios::in);
std::string input_cache;
int line = 0;
std::vector<class Example*>population;
while( std::getline(inFile, input_cache)){
std::istringstream line_cache(input_cache);
double risk, income;
line_cache>>risk>>income;
Example*tempExample = new Example();
tempExample->assign(risk, income);
population.push_back(tempExample);
}
std::cout<<"Population:"<<population.size()<<std::endl;
std::vector<class Example*>outPopulation;
for(int i = 0; i<population.size(); i++){
bool dominated = false;
for(int j = 0; j<population.size(); j++){
if(dom(*population[j], *population[i])){
dominated = true;
break;
}
}
if(!dominated){
population[i]->echo();
outPopulation.push_back(population[i]);
}
}
std::cout<<"Population:"<<outPopulation.size()<<std::endl;
ofstream outFile;
outFile.open("Output/MOEA-D/Test4/initEP1.txt");
}
int main(int argc, char *argv[]){
std::vector<class Example>x;
for(int i = 0; i<10; i++){
Example tempX;
x.push_back(tempX);
}
x.erase(x.begin()+3);
//testDom();
/*
Example x;
x.assign(18.715, 1.17502);
Example y;
y.assign(17.0082, 1.77234);
if(dom(x,y)){
std::cout<<"ok\n";
}*/
}