-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from elsoroka/dev-ints-reals
Merge ints and reals into dev
- Loading branch information
Showing
16 changed files
with
972 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
push!(LOAD_PATH,"../src/") | ||
using BooleanSatisfiability | ||
|
||
# From https://microsoft.github.io/z3guide/docs/theories/Arithmetic/ | ||
# Job shop scheduling problem is a linear integer problem arising in operations research. | ||
# Suppose you are managing a machine shop with several different jobs in progress. | ||
# Each job consists of a series of tasks. Some of the tasks have ordering constraints: e.g. parts must be manufactured before they can be installed in a larger assembly. | ||
# Due to equipment constraints, you cannot schedule two tasks requiring the same machine at the same time. | ||
# Additionally, all tasks must have a worker assigned to complete them. | ||
|
||
# In this problem we have three jobs, each consisting of one task to be completed first by worker A and one to be completed next by worker B. | ||
# Each task has an integer-valued duration. Workers cannot work on two tasks at once or take each others' tasks. | ||
# We'd like to find a solution such that all three jobs can be completed in an 8-hour workday. | ||
# Define two vector-valued variables t1 and t2 such that tj[i] is the start time of job i for worker j. | ||
# Define two vector-valued variables d1 and d2 such that dj[i] is the duration of job i for worker j. | ||
|
||
n = 3 # number of jobs | ||
m = 2 # number of tasks per job | ||
t1 = Int(n,"t1") | ||
t2 = Int(n, "t2") | ||
d1 = [2; 3; 2] | ||
d2 = [1; 1; 3] | ||
|
||
# A start time of 0 corresponds to the first hour of the workday, and an end time of 8 corresponds to the last hour of the workday. | ||
working_hours = all(and.(t1 .>= 0, t2 .+ d2 .<= 8)) | ||
|
||
# Sequencing constraint: For each job, A must complete the first task before B can start the second task | ||
sequencing = and(t2 .>= t1 .+ d1) | ||
|
||
# Overlap constraint between all permutations | ||
overlaps = [(1,2), (1,3), (2,3)] | ||
overlap_1 = all([or( t1[i] >= t1[j] + d1[j], t1[j] >= t1[i] + d1[i]) for (i,j) in overlaps]) | ||
overlap_2 = all([or( t2[i] >= t2[j] + d2[j], t2[j] >= t2[i] + d2[i]) for (i,j) in overlaps]) | ||
|
||
status = sat!(working_hours, sequencing, overlap_1, overlap_2) | ||
println("status = $status") | ||
println("t1 = $(value(t1))") | ||
println("t2 = $(value(t2))") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.