66 lines
1.4 KiB
C++
Executable File
66 lines
1.4 KiB
C++
Executable File
#include<math.h>
|
|
#include<vector>
|
|
#include "costfunctions.h"
|
|
|
|
/*
|
|
* Lest squared cost
|
|
*/
|
|
|
|
Khi2::Khi2(){
|
|
std::vector<std::vector<double>> T1;
|
|
std::vector<std::vector<double>> T2;
|
|
k_exp = T1;
|
|
k_mod = T2;
|
|
}
|
|
|
|
Khi2::Khi2(const Khi2& other):k_exp(other.k_exp),k_mod(other.k_mod){}
|
|
|
|
Khi2::Khi2(std::vector<std::vector<double>> T1,std::vector<std::vector<double>> T2): k_exp(T1), k_mod(T2){}
|
|
|
|
void Khi2::setData(std::vector<std::vector<double>> T1, std::vector<std::vector<double>> T2){
|
|
k_exp = T1;
|
|
k_mod = T2;
|
|
}
|
|
|
|
double Khi2::get() const {
|
|
double S=0,temp=0;
|
|
for(int i=0;i<k_exp.size();i++){
|
|
temp = S;
|
|
S = temp + pow(k_exp[i][1]-k_mod[i][1],2);
|
|
}
|
|
return S;
|
|
}
|
|
|
|
/*
|
|
* Total distance
|
|
*/
|
|
|
|
Distance::Distance(){
|
|
std::vector<std::vector<double>> T1;
|
|
std::vector<int> T2;
|
|
d_pos = T1;
|
|
d_ord = T2;
|
|
}
|
|
|
|
Distance::Distance(const Distance& other):d_pos(other.d_pos),d_ord(other.d_ord){}
|
|
|
|
Distance::Distance(std::vector<std::vector<double>> T1, std::vector<int> T2): d_pos(T1), d_ord(T2){}
|
|
|
|
void Distance::setData(std::vector<std::vector<double>> T1, std::vector<int> T2){
|
|
d_pos = T1;
|
|
d_ord = T2;
|
|
}
|
|
|
|
double Distance::get() const {
|
|
double S=0,temp=0,x1=0,y1=0,x2=0,y2=0;
|
|
for(int i=0;i<d_pos.size()-1;i++){
|
|
x1 = d_pos[d_ord[i]][0];
|
|
y1 = d_pos[d_ord[i]][1];
|
|
x2 = d_pos[d_ord[i+1]][0];
|
|
y2 = d_pos[d_ord[i+1]][1];
|
|
temp = S;
|
|
S = temp + sqrt(pow(x2-x1,2)+pow(y2-y1,2));
|
|
}
|
|
return S;
|
|
}
|