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
19ebcccd
Commit
19ebcccd
authored
2 years ago
by
Goes,M. (Martijn)
Browse files
Options
Downloads
Patches
Plain Diff
fix: some constraints, more to do
parent
5fb1b40d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
__pycache__/offline.cpython-310.pyc
+0
-0
0 additions, 0 deletions
__pycache__/offline.cpython-310.pyc
offline.py
+65
-33
65 additions, 33 deletions
offline.py
t4_in.txt
+1
-1
1 addition, 1 deletion
t4_in.txt
t4_out.txt
+3
-9
3 additions, 9 deletions
t4_out.txt
with
69 additions
and
43 deletions
__pycache__/offline.cpython-310.pyc
+
0
−
0
View file @
19ebcccd
No preview for this file type
This diff is collapsed.
Click to expand it.
offline.py
+
65
−
33
View file @
19ebcccd
...
...
@@ -32,6 +32,7 @@ def Solve(images, blackouts):
"""
PARAMETERS
"""
h
=
GRB
.
INFINITY
# time horizon = infinite
tfU_j
=
GRB
.
INFINITY
# YA_t_br = [] # both not used
# YB_t_br = []
...
...
@@ -39,10 +40,10 @@ def Solve(images, blackouts):
""""
DECISION VARIABLES
"""
# makespan
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)
#
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 i
s
whitebox t
Tf_t
=
model
.
addVars
(
whitebox_count
,
lb
=
0
,
vtype
=
GRB
.
CONTINUOUS
)
# finish of all images i
n
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
...
...
@@ -52,6 +53,10 @@ def Solve(images, blackouts):
YB_j_br
=
model
.
addVars
(
image_count
,
blackout_count
,
vtype
=
GRB
.
BINARY
)
# order j finishes before blackbox br
"""
CONSTRAINTS
"""
# model.addConstr(Y_j_jprime[0,0] == 0)
# model.addConstr(Y_j_jprime[0,1] == 0)
# model.addConstr(Y_j_jprime[1,0] == 1)
# model.addConstr(Y_j_jprime[1,1] == 0)
# (1) minimize makespan
model
.
setObjective
(
ms
,
GRB
.
MINIMIZE
)
# (3)
...
...
@@ -63,6 +68,21 @@ def Solve(images, blackouts):
for
j
in
range
(
image_count
)
for
jprime
in
range
(
image_count
)),
name
=
"
Eq(4)
"
)
# (4 v2)
# model.addConstrs((Tf_j[j] <= Ts_j[jprime] + tfU_j * (1 - Y_j_jprime[j,jprime])
# for j in range(image_count)
# for jprime in range(image_count)),
# name="Eq(4 v2)")
# (4 v3)
# for j in range(image_count):
# for jprime in range(j+1,image_count):
# model.addConstr((Tf_j[j] <= Ts_j[jprime] + tfU_j * (1 - Y_j_jprime[j,jprime])),
# name="Eq(4 v2)")
# # (5 v3)
# for j in range(image_count):
# for jprime in range(j+1,image_count):
# model.addConstr((Tf_j[jprime] <= Ts_j[j] + tfU_j * (1 + Y_j_jprime[j,jprime])),
# name="Eq(5 v3)")
# (9)
model
.
addConstrs
((
ms
>=
Tf_j
[
j
]
for
j
in
range
(
image_count
)),
...
...
@@ -77,7 +97,8 @@ def Solve(images, blackouts):
name
=
"
Eq(13)
"
)
# (17)
model
.
addConstrs
((
gp
.
quicksum
(
X_j_t
[
j
,
t
]
for
j
in
range
(
image_count
))
+
Xfree_t
[
t
]
==
1
+
Xfree_t
[
t
]
==
1
for
t
in
range
(
whitebox_count
)),
name
=
"
Eq(17)
"
)
# (19)
...
...
@@ -91,15 +112,15 @@ def Solve(images, blackouts):
for
t
in
range
(
whitebox_count
)),
name
=
"
Eq(20)
"
)
# (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
)),
name
=
"
Eq(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)),
#
name="Eq(32)")
# (33)
model
.
addConstrs
((
P_j_br
[
j
,
br_index
]
==
0
for
j
in
range
(
image_count
)
for
br_index
in
range
(
blackout_count
)),
name
=
"
Eq(33)
"
)
#
model.addConstrs((P_j_br[j,br_index] == 0 for j in range(image_count)
#
for br_index in range(blackout_count)),
#
name="Eq(33)")
# (34)
model
.
addConstrs
((
br
[
br_index
][
1
]
*
YA_j_br
[
j
,
br_index
]
<=
Ts_j
[
j
]
for
br_index
in
range
(
blackout_count
)
...
...
@@ -124,36 +145,47 @@ def Solve(images, blackouts):
# SOLVE AND PRINT THE RESULTS
model
.
optimize
()
res
=
printSolution
(
model
)
return
(
res
[
0
],
res
[
1
])
time
=
-
1
starts
=
[
-
1
]
if
model
.
status
==
GRB
.
OPTIMAL
:
deletus
=
starts
.
pop
()
time
=
model
.
ObjVal
print
(
'
\n
Finish time: %g
'
%
time
)
print
(
"
White box decision variables:
"
)
for
(
j
,
t
)
in
X_j_t
:
print
(
f
"
(im
{
j
}
,wb
{
t
}
) =
{
X_j_t
[
j
,
t
].
X
}
"
)
print
(
'
\n
Times:
'
)
for
im
in
Ts_j
:
ts
=
Ts_j
[
im
].
X
tf
=
Tf_j
[
im
].
X
print
(
f
"
Image
{
im
}
starts t=
{
ts
}
finishes t=
{
tf
}
"
)
starts
.
append
(
t
)
print
(
'
\n
Order:
'
)
for
im
in
Ts_j
:
for
im2
in
Ts_j
:
print
(
f
"
{
im
}
before
{
im2
}
:
{
Y_j_jprime
[
im
,
im2
].
X
}
"
)
print
(
'
\n
Whitebox contains:
'
)
for
t
in
PV_t
:
print
(
f
"
wb
{
t
}
is
{
Xfree_t
[
t
].
X
}
empty and holds length
{
PV_t
[
t
].
X
}
of images
"
)
print
(
'
\n
Blackboxes before/after:
'
)
for
(
j
,
br_index
)
in
YA_j_br
:
print
(
f
"
YA_
{
j
}
_
{
br_index
}
: image
{
j
}
after blackbox
{
br_index
}
=
{
YA_j_br
[
j
,
br_index
].
X
}
"
)
print
(
f
"
YB_
{
j
}
_
{
br_index
}
: image
{
j
}
before blackbox
{
br_index
}
=
{
YB_j_br
[
j
,
br_index
].
X
}
"
)
def
printSolution
(
model
):
if
model
.
status
==
GRB
.
OPTIMAL
:
print
(
'
\n
Finish time: %g
'
%
model
.
ObjVal
)
else
:
print
(
'
\n
No solution, reason:
'
)
iis
=
model
.
computeIIS
()
# Irreducible Infeasible Subsystem, https://support.gurobi.com/hc/en-us/articles/360029969391-How-do-I-determine-why-my-model-is-infeasible-
print
(
iis
)
# time = None
# 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)
# else:
# time = "No solution"
# return (41.618, [35, 29.6, 18, 35.618, 0.86]) # answer to test instance 0
return
(
45
,
[
22
,
4
,
35
,
42
,
0
,
5
,
28
,
11
])
# answer to test instance 1
#
return (time,
timeStep
s)
#
return (45, [22, 4, 35, 42, 0, 5, 28, 11]) # answer to test instance 1
return
(
time
,
start
s
)
def
calculate_whiteboxes
(
blackouts
):
wb
=
[]
...
...
This diff is collapsed.
Click to expand it.
t4_in.txt
+
1
−
1
View file @
19ebcccd
...
...
@@ -2,4 +2,4 @@
10
15
1
50, 10
\ No newline at end of file
25, 5
\ No newline at end of file
This diff is collapsed.
Click to expand it.
t4_out.txt
+
3
−
9
View file @
19ebcccd
45
22
4
35
42
0
5
28
11
\ No newline at end of file
15.0
1
1
\ No newline at end of file
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