Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
TelescopeScheduling
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ADS
TelescopeScheduling
Commits
709ce274
Commit
709ce274
authored
2 years ago
by
Hamers,G.C.A. (Glenn)
Browse files
Options
Downloads
Patches
Plain Diff
added constraints (see google docs)
parent
16897249
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
offline.py
+65
-12
65 additions, 12 deletions
offline.py
with
65 additions
and
12 deletions
offline.py
+
65
−
12
View file @
709ce274
...
...
@@ -12,8 +12,8 @@ def Solve(images, blackouts):
"""
Refer to the Google Docs file for full explanation
SETS / INDICES
"""
br
=
blackouts
# tuples (b^L_br, b^U_br) = [start, end)
j
=
images
# real number p_j = image size
t
=
calculate_whiteboxes
(
blackouts
)
# tuples (time_t, δ_t) = [start, end)
j
s
=
images
# real number p_j = image size
t
s
=
calculate_whiteboxes
(
blackouts
)
# tuples (time_t, δ_t) = [start, end)
"""
PARAMETERS
"""
h
=
float
(
'
inf
'
)
# time horizon = infinite
...
...
@@ -23,13 +23,13 @@ def Solve(images, blackouts):
""""
DECISION VARIABLES
"""
# makespan
ms
=
model
.
addVar
(
0
,
vtype
=
GRB
.
CONTINUOUS
)
# makespan, objective function minimization value, bounded with constraints
P_j_br
=
model
.
addVars
((
image_count
,
blackout_count
),
0
,
vtype
=
GRB
.
CONTINUOUS
)
# preemption time, will be set to 0 in Eq (33)
PV_t
=
model
.
addVars
(
whitebox_count
,
0
,
vtype
=
GRB
.
CONTINUOUS
)
# sum of length of images in whitebox t
Tf_j
=
model
.
addVars
(
image_count
,
0
,
vtype
=
GRB
.
CONTINUOUS
)
# finish of image j
Tf_t
=
model
.
addVars
(
whitebox_count
,
0
,
vtype
=
GRB
.
CONTINUOUS
)
# finish of all images is whitebox t
Ts_j
=
model
.
addVars
(
image_count
,
0
,
vtype
=
GRB
.
CONTINUOUS
)
# start of image j
Ts_t
=
model
.
addVars
(
whitebox_count
,
0
,
vtype
=
GRB
.
CONTINUOUS
)
# start of timeslot t, probably redundant
ms
=
model
.
addVar
(
lb
=
0
,
vtype
=
GRB
.
CONTINUOUS
)
# makespan, objective function minimization value, bounded with constraints
P_j_br
=
model
.
addVars
((
image_count
,
blackout_count
),
lb
=
0
,
vtype
=
GRB
.
CONTINUOUS
)
# preemption time, will be set to 0 in Eq (33)
PV_t
=
model
.
addVars
(
whitebox_count
,
lb
=
0
,
vtype
=
GRB
.
CONTINUOUS
)
# sum of length of images in whitebox t
Tf_j
=
model
.
addVars
(
image_count
,
lb
=
0
,
vtype
=
GRB
.
CONTINUOUS
)
# finish of image j
Tf_t
=
model
.
addVars
(
whitebox_count
,
lb
=
0
,
vtype
=
GRB
.
CONTINUOUS
)
# finish of all images is whitebox t
Ts_j
=
model
.
addVars
(
image_count
,
lb
=
0
,
vtype
=
GRB
.
CONTINUOUS
)
# start of image j
Ts_t
=
model
.
addVars
(
whitebox_count
,
lb
=
0
,
vtype
=
GRB
.
CONTINUOUS
)
# start of timeslot t, probably redundant
X_j_t
=
model
.
addVars
((
image_count
,
whitebox_count
),
vtype
=
GRB
.
BINARY
)
# order j in whitebox t
Xfree_t
=
model
.
addVars
(
whitebox_count
,
vtype
=
GRB
.
BINARY
)
# whitebox t has no images in it
Y_j_jprime
=
model
.
addVars
((
image_count
,
image_count
),
vtype
=
GRB
.
BINARY
)
# image j comes before image j' in the global order
...
...
@@ -37,12 +37,64 @@ def Solve(images, blackouts):
YB_j_br
=
model
.
addVars
((
image_count
,
blackout_count
),
vtype
=
GRB
.
BINARY
)
# order j finishes before blackbox br
"""
CONSTRAINTS
"""
# (1) minimize makespan
model
.
setObjective
(
ms
,
GRB
.
MINIMIZE
)
# (3)
model
.
addConstrs
(
Tf_j
[
j
]
-
Ts_j
[
j
]
==
js
[
j
]
for
j
in
range
(
image_count
))
# (4)
model
.
addConstrs
(
Tf_j
[
j
]
*
Y_j_jprime
[
j
,
jprime
]
<=
Ts_j
[
j
]
*
Y_j_jprime
[
j
,
jprime
]
for
j
in
range
(
image_count
)
for
jprime
in
range
(
image_count
))
# (9)
model
.
addConstrs
(
ms
>=
Tf_j
[
j
]
for
j
in
range
(
image_count
))
# (11)
model
.
addConstrs
(
Ts_t
[
t
+
1
]
>=
Tf_t
[
t
]
for
t
in
range
(
whitebox_count
-
1
))
# (13)
model
.
addConstrs
(
Tf_t
[
t
]
-
Ts_t
[
t
]
==
PV_t
[
t
]
for
t
in
range
(
whitebox_count
))
# (17)
model
.
addConstrs
(
gp
.
quicksum
(
X_j_t
[
j
,
t
]
for
j
in
range
(
image_count
))
+
Xfree_t
[
t
]
==
1
for
t
in
range
(
whitebox_count
))
# (19)
model
.
addConstrs
(
gp
.
quicksum
(
X_j_t
[
j
,
t
]
for
t
in
range
(
whitebox_count
))
==
1
for
j
in
range
(
image_count
))
# (20)
model
.
addConstrs
(
PV_t
[
t
]
==
gp
.
quicksum
(
js
[
j
]
*
X_j_t
[
j
,
t
]
for
j
in
range
(
image_count
))
for
t
in
range
(
whitebox_count
))
# (32)
model
.
addConstrs
(
YB_j_br
[
j
,
br_index
]
+
YA_j_br
[
j
,
br_index
]
==
X_j_t
[
j
,
t
]
for
j
in
range
(
image_count
)
for
t
in
range
(
whitebox_count
)
for
br_index
in
range
(
blackout_count
))
# (33)
model
.
addConstrs
(
P_j_br
[
j
,
br_index
]
==
0
for
j
in
range
(
image_count
)
for
br_index
in
range
(
blackout_count
))
# (34)
model
.
addConstrs
(
br
[
br_index
][
1
]
*
YA_j_br
[
j
,
br_index
]
<=
Ts_j
[
j
]
for
br_index
in
range
(
blackout_count
)
for
j
in
range
(
image_count
))
# (35)
model
.
addConstrs
(
Ts_j
[
j
]
<=
br
[
br_index
][
0
]
*
YB_j_br
[
j
,
br_index
]
+
YA_j_br
[
j
,
br_index
]
*
float
(
'
inf
'
)
for
j
in
range
(
image_count
)
for
br_index
in
range
(
blackout_count
))
# (36)
model
.
addConstrs
(
br
[
br_index
][
1
]
*
YA_j_br
[
j
,
br_index
]
<=
Tf_j
for
br_index
in
range
(
blackout_count
)
for
j
in
range
(
image_count
))
# (37)
model
.
addConstrs
(
Tf_j
[
j
]
<=
br
[
br_index
][
0
]
*
YB_j_br
[
j
,
br_index
]
for
j
in
range
(
image_count
)
for
br_index
in
range
(
blackout_count
))
# SOLVE AND PRINT THE RESULTS
model
.
optimize
()
print
(
f
"
model.status =
{
model
.
status
}
; MS =
{
model
.
ObjVal
}
"
)
# printSolution(model)
def
printSolution
(
model
):
...
...
@@ -50,13 +102,14 @@ def printSolution(model):
timeSteps
=
[]
if
model
.
status
==
GRB
.
OPTIMAL
:
time
=
None
# TODO: loop over decision variables
# i.e. for all images in whitebox j:
# their order does not matter
# so just paste them behind each other
# timeSteps.append(decVariables[x_ij].X)
timeSteps
.
append
(
1234
)
#
timeSteps.append(1234)
else
:
time
=
"
No solution
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment