-
Notifications
You must be signed in to change notification settings - Fork 1
/
spin.cpp
executable file
·73 lines (49 loc) · 1.5 KB
/
spin.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
/***************************************************************************
* Copyright (C) 2015 Tian-Li Yu and Shih-Huan Hsu *
* tianliyu@ntu.edu.tw *
***************************************************************************/
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include "spin.h"
using namespace std;
double evaluateSPIN(int *x, SPINinstance *inst) {
int temp=1, counter=1;
double result=0;
for(vector<int>::iterator it = inst->fvector.begin(); it != inst->fvector.end(); it++) {
if (counter%3 != 0) temp *= x[*it-1];
else{
temp *= *it;
result += temp;
temp=1;
}
counter++;
}
return result/(double)inst->ell;
}
void loadSPIN(char *cnf_file_name, SPINinstance *inst) {
int temp;
ifstream input;
string line;
input.open ( cnf_file_name );
getline ( input, line );
istringstream first( line );
first >> inst->ell;
getline ( input, line );
istringstream second( line );
second >> inst->opt;
inst->opt *= -1;
while(getline ( input, line )){
if (line[0] == '\0') continue;
istringstream in( line );
while ( in >> temp ) inst->fvector.push_back(temp);
}
if ((int)inst->fvector.size() != inst->ell*6){
cout << "Instance Error" << endl;
exit(0);
}
}