-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConsoleApplication1.cpp
More file actions
112 lines (96 loc) · 2.78 KB
/
Copy pathConsoleApplication1.cpp
File metadata and controls
112 lines (96 loc) · 2.78 KB
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
#include <iostream>
#include <fstream>
#include <ctime>
#include "gurobi_c++.h"
#include "settings.h"
#include "node.h"
#include "validity.h"
#include "randominput.h"
#include "adjust.h"
#include "Command.h"
#include "Visualizer.h"
using namespace std;
int main()
{
srand((unsigned int)time(0));
try {
GRBEnv env = GRBEnv(true);
env.set("LogFile", "SP.log");
env.start();
int d,tn;
cout << "d=? (As the method proposed by the paper requires huge amount of computation, we suggest the value of d no more than 9)" << endl;
cin >> d;
cout << "Number of target concentrations? (No more than 3)" << endl;
cin >> tn;
int m, n;
cout << "The size of the chip: m=? n=?" << endl;
cin >> m >> n;
int* p2 = new int[d + 1]; //p2[j]=2^j
p2[0] = 1;
for (int i = 1; i <= d; i++) {
p2[i] = p2[i - 1] * 2;
}
GRBModel model = GRBModel(env);
Node** NF = new Node * [d + 1];
Node Source(-1, 0, SRC);
Node Waste(d + 1, -1, WST);
Node Sink(d + 1, -2, SNK);
for (int i = 0; i < 100; ++i) {
SPInput I=random(d,tn,WASTE);
//SPInput I(7, 1, 1, { 96,9,43 }, { 1,1,1 });
//SPInput I(7, 1, 1, { 36,81,93 }, { 1,1,1 });
//SPInput I(7, 1, 1, { 23,26,64,109 }, { 1,1,1,1 });
if (i == 0) {
SPBuild(I, &model, NF, Source, Sink, Waste);
}
else {
SPAdjust(I, &model, NF, Source, Sink, Waste);
}
model.optimize();
/*SBWD result;
if (check(I, NF, Source, result)) {
cout << "Sample preparation is correct." << endl;
}
else
cout << "Sample preparation is wrong." << endl;*/
DropletTracker D(d);
vector<StepInfo> stepinfo;
D.process(NF, Source, stepinfo);
/*int cmdnum = stepinfo.size();
cout << cmdnum << endl;
for (int x = 0; x < cmdnum; ++x) {
cout << "Command " << x + 1 << ":\n";
if (stepinfo[x].buffer) cout << "Release buffer droplet\n";
if (stepinfo[x].sample) cout << "Release sample droplet\n";
cout << "Merge " << stepinfo[x].merge1 << " and " << stepinfo[x].merge2 << endl;
if (stepinfo[x].waste >= 0) cout << "Sink a droplet of concentration " << stepinfo[x].waste << endl;
}*/
cout << "Target concentration: " << endl;
for (int i = 0; i < I.TC.size(); ++i) {
cout << I.TC[i] << " ";
}
cout << endl;
Command cmd(m, n, d);
cmd.initialize(stepinfo);
Chip chip(m, n);
Visualizer vis;
while (cmd.update(chip)) {
//vis.draw(chip);
cout << chip << endl;
}
}
for (int j = 0; j < d + 1; ++j) {
delete[]NF[j];
}
delete[]NF;
delete[]p2;
}
catch (GRBException e) {
cout << "Error code = " << e.getErrorCode() << endl;
cout << e.getMessage() << endl;
}
catch (...) {
cout << "Exception during optimization" << endl;
}
return 0;
}