-
Notifications
You must be signed in to change notification settings - Fork 0
/
No onboard process.py
199 lines (139 loc) · 5.92 KB
/
No onboard process.py
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 18 11:23:40 2022
@author: iainh
"""
# no on board processing version of code
# CP model tester, not for long term use
import math
import pandas as pd
from ortools.sat.python import cp_model
from Solver.CPModel_SC import CPModel_SC_data, CPModel_SC_No_process
from Solver.HintFunctions import CreateManHint, AddHint
from utils import plotFunctions as pf
from utils import postProcessing as post
from utils import readwrite
affix = "pol/10s_15d/G40/"
#read in if a illuminator is in view
data = pd.read_csv("Data/"+ affix+"Illuminator view data log.csv")
any_ilum_list = data.values.tolist()
#read in the downlink data times
data = pd.read_csv("Data/"+ affix+"Communications Data log.csv")
datals= data.values.tolist()
# reads in which illuminators are visible
data = pd.read_csv("Data/"+ affix+"Avg objects Detection log.csv")
ilum_value_list = data.values.tolist()
# chages downlink from list of lists to 1D list
gnd_stat_list = [datals[i][0] for i in range(0, len(datals))]
# used to define how long it takes to process each dataset
FLOP_to_proc = 1000
FLOPS_available = 100 # giga flops
hint = 0
switching_constraint=1
switchtime = 1
target_print = 0
interval = 10000# length of interval to be optimised
start_shift=0
obs_dataset_mem = int( 150e3/100 )# in 0.1 kB
obs_rate = 100 # used to allow the observations to be processed in parts while remaining integers
pro_rate = math.ceil(FLOP_to_proc/FLOPS_available) # rate at which the system can process a dataset
pro_dataset_mem = int(300 /100) # in 0.1 kB
down_rate_mem = 320 # in 0.1 kB per second
down_rate = int(down_rate_mem/pro_dataset_mem) # the number of processed dataset units the satellite can downlink per second
down_dataset_mem = int(down_rate_mem/down_rate)
memory_init = 0
num_obs_init = 0
num_pro_init=0
num_down_init = 0
memory_storage = int( 64e7) # 64GB total memory in 0.1kB
num_obs_init = 0
all_T = range(interval)
all_action = range(4)
all_sats = range(66)
dt = 60
time = [dt*t for t in all_T]
for t in all_T:
for sat in all_sats:
ilum_value_list[t][sat] = math.floor(ilum_value_list[t][sat]*10000)
'''
Creating Hint
'''
if hint == 1:
#add code to make hint
(hint_shifts, hint_target_ilum) = CreateManHint(any_ilum_list,ilum_value_list, gnd_stat_list, all_action,all_T, all_sats, obs_dataset_mem, obs_rate, pro_dataset_mem,
pro_rate, down_rate, memory_init, memory_storage, num_obs_init,num_pro_init, dt)
'''
creating cp model
'''
(model, shifts, target_ilum, num_obs, num_pro, num_down, memory, Log) = CPModel_SC_No_process(any_ilum_list,gnd_stat_list, interval,start_shift, obs_dataset_mem, obs_rate, pro_dataset_mem,
pro_rate, down_rate,down_dataset_mem, memory_init, memory_storage, num_obs_init, num_pro_init, num_down_init,dt, ilum_value_list,switchtime,switching_constraint)
print("CP Model made")
if hint ==1:
(model, shifts, target_ilum) = AddHint(model, shifts, target_ilum, hint_shifts, hint_target_ilum, all_T, all_action, all_sats)
'''
solving the CP model
'''
solver = cp_model.CpSolver()
solver.parameters.max_time_in_seconds =200
solver.parameters.log_search_progress = True
solver.parameters.num_search_workers = 4
status = solver.Solve(model)
if status == cp_model.OPTIMAL :
print('Solution: optimal found')
print(f'Objective value achieved = {solver.ObjectiveValue()} ')
print('\nStatistics')
print(' - conflicts : %i' % solver.NumConflicts())
print(' - branches : %i' % solver.NumBranches())
print(' - wall time : %f s' % solver.WallTime())
elif status == cp_model.FEASIBLE:
print('Solution: feasible found')
print(f'Objective value achieved = {solver.ObjectiveValue()} ')
print('\nStatistics')
print(' - conflicts : %i' % solver.NumConflicts())
print(' - branches : %i' % solver.NumBranches())
print(' - wall time : %f s' % solver.WallTime())
else:
print('Solution: no feasible solution found')
if target_print ==1:
post.target_printer(solver,shifts, target_ilum, ilum_value_list, all_T,all_action,all_sats)
'''
post processing
'''
# Creates pd dataframe to then be used to make gantt chart
titles = ['Observing', 'Processing', 'downlinking', 'idling', 'num observed', 'num processed', 'num downlinked', 'memory used (kB)', 'Any Satellite targeted']
data = []
actionABS = []
scheduleWrite = [[0 for a in range(9)] for s in all_T]
schedule = [[0 for s in all_T] for a in all_action]
target_ilum_val = [[0 for s in all_T] for sat in all_sats]
target_ilum_val_inv = [[0 for sat in all_sats] for s in all_T]
for s in all_T:
for a in all_action:
if solver.Value(shifts[(a,s)]) == 1:
actionABS.append(titles[a])
scheduleWrite[s][a] = 1
schedule[a][s] = 1
for i in range(4):
multi =1
if i ==3:
multi = 0.1
scheduleWrite[s][i+4] = multi*solver.Value(Log[i][s])
for sat in all_sats:
if solver.Value(target_ilum[(sat,s)]) == 1:
target_ilum_val[sat][s] = 1
target_ilum_val_inv[s][sat] = 1
if sum(target_ilum_val[sat][s] for sat in all_sats) > 0:
scheduleWrite[s][8] = 1
tempDict = dict(start = s*dt, duration = dt, end = (s+1)*dt, action = actionABS[s])
data.append(tempDict)
df = pd.DataFrame(data)
readwrite.xlsxOut(scheduleWrite,titles, "scheduleraw.xlsx", "./results/"+affix)
titles = []
for sat in all_sats:
temp = "Sat_%i" % (sat)
titles.append(temp)
readwrite.xlsxOut(target_ilum_val_inv, titles, "illuminator targeted.xlsx", "./results/")
pf.ganttChart(df,titles)
(memoryLogs, num_logs) = post.memoryLogAssem(schedule, obs_dataset_mem, pro_dataset_mem, obs_rate, pro_rate, down_rate,dt)
pf.memoryGraph(memoryLogs,time)
pf.ObsValueGraph(ilum_value_list,target_ilum_val, schedule, time, all_T, all_sats)