-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTomas_DowloadPlanner
122 lines (101 loc) · 4.87 KB
/
Tomas_DowloadPlanner
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
114
115
116
117
118
119
120
121
122
/** Number of download opportunities */
int TotalMissionTime = ...;
int NdownloadWindows = ...;
int Ncandidates = ...;
/** Download range */
range DownloadWindows = 1..NdownloadWindows;
range DownloadWindowsPlusZero = 0..NdownloadWindows;
range DownloadCandidates = 1..Ncandidates;
range DownloadCandidatesPlusZero = 0..Ncandidates;
/** Index of the download */
int CandidateDownload[DownloadCandidates] = ...;
/** "Cost" of each download */
float CostFunc[DownloadCandidates] = ...;
/** Index of the download window */
int DownloadWindow[DownloadWindows] = ...;
///** Candidate download quota */
//float CandidateDownloadQuota[DownloadCandidates] = ...;
///** Candidate download priority */
//int CandidateDowloadPri[DownloadCandidates] = ...;
/** Earliest start time for download candidate */
float EarliestStartTime[DownloadCandidates] = ...;
/** End time for download window */
float WindowEndTime[DownloadWindows] = ...;
/** Start time for download window */
float WindowStartTime[DownloadWindows] = ...;
/** Download duration associated with each acquisition window */
float Duration[DownloadCandidates] = ...;
///** Download candidate propability */
//float cloudProba[DownloadCandidates] = ...;
///** Download candidate zenith angle */
//float Zenangle[DownloadCandidates] = ...;
/** File in which the result will be written */
string OutputFile = ...;
/** Boolean variable indicating whether a download candidate is selected */
dvar int selectDown[DownloadCandidatesPlusZero] in 0..1;
/** Boolean matrix indicating the window allocation of download candidates */
dvar int selectWin[DownloadCandidatesPlusZero][NdownloadWindows] in 0..1;
/** next[a1][a2] = 1 when a1 is the selected download candidate that precedes a2 */
dvar int next[DownloadCandidatePlusZero][DownloadCandidatePlusZero] in 0..1;
/** Acquisition start time in each acquisition window */
dvar float+ startTime[a in DownloadCandidates] in EarliestStartTime[a]..TotalMissionTime;
dexpr float downsum = sum(c in DownloadCandidates) selectDown[c];
dexpr float costsum = sum(c in DownloadCandidates) CostFunc[c]*selectDown[c];
execute{
cplex.tilim = 60; // 60 seconds
}
// maximize the value of the download windows selected
maximize sum(c in DownloadCandidates) CostFunc[c]*selectDown[c];
constraints {
// The same candidate cannot be repeated (for different download windows)
forall(c in DownloadCandidates){
sum(w in DownloadWindows) selectWin[c][w] <= 1;
// sum(w in DownloadWindows) selectWin[c][w] <= selectDown[c];
}
// default selection of the dummy download windows numbered by 0 and -1 (one for each satellite)
forall(w in DownloadWindows){
//selectWin[0][w] == 1;
selectDown[0] = 1;
}
// A download window is selected if and only if it has a (unique) precedessor and a (unique)
// successor in the plan that shares the same satellite
forall(c1 in DownloadCandidatesPlusZero){
sum(c2 in DownloadCandidatesPlusZero : c2 != c1 ) next[c1][c2] == sum(w in DownloadWindows) selectWin[c1][w];
sum(c2 in DownloadCandidatesPlusZero : c2 != c1 ) next[c2][c1] == sum(w in DownloadWindows) selectWin[c1][w];
next[c1][c1] == 0;
}
// Window fitting condition --> #TODO: Put selectDown in here, for heuristic
forall(c in DownloadCandidate, w in DownloadWindows){
startTime[c] > (1-selectWin[c][w])*(WindowEndTime[w]-Duration[c]-WindowStartTime[w]) + WindowStartTime[w];
startTime[c] < (1-selectWin[c][w])*(WindowStartTime[w]-WindowEndTime[w] + Duration[c]) + WindowEndTime[w] - Duration[c];
}
// Temporal separation constraints between successive download candidates (big-M formulation)
forall(c1,c2 in DownloadWindows : c1 != c2 ){
// startTime[c1] + Duration[c1] <= startTime[c2]
// + (1-next[c1][c2])*( (TotalMissionTime - Duration[c1]) + Duration[c1] - EarliestStartTime[c2] );
startTime[c1] + Duration[c1] <= startTime[c2]
+ (1-next[c1][c2])*TotalMissionTime;
}
// // Temporal separation constraints between successive acquisition windows (big-M formulation)
// forall(a1,a2 in AcquisitionWindows : a1 != a2 && SatelliteIdx[a1] == SatelliteIdx[a2] && EarliestStartTime[a1] + Duration[a1] + TransitionTimes[a1][a2] < LatestStartTime[a2]){
// startTime[a1] + Duration[a1] <= startTime[a2]
// + (1-next[a1][a2])*(LatestStartTime[a1]+Duration[a1]-EarliestStartTime[a2]);
// }
// Temporal heuristics for speeding the code up:
//
}
execute {
for(var i=1; i <= Ncandidates; i++){
writeln(CostFunc[i]*selectDown[i]);
}
writeln("costsum: " + costsum + " #downloads: " + downsum);
// Writes the .txt file, that follows the matrix structure
// ( Candidate Down idx | Down start time | Down end time )
// Satellite column will probably not be read by java, but can help user to verify results
var ofile = new IloOplOutputFile(OutputFile);
for(var i=1; i <= Ncandidates; i++) {
if(selectDown[i] == 1){
ofile.writeln(CandidateDownloads[i] + " " + startTime[i] + " " + (startTime[i]+Duration[i]));
}
}
}