I'm working on a production planning project, so I want to find an order production start time in some machines(A, B).
For simplification purpose, I suppose that I have 2 machines(machine A and machine B) I have following constraints:
Each machine can work on some times of day only (
A_TimeLimitation
,B_TimeLimitation
) for simplification purpose I supposed thatmachine A can work in following ranges:
(2014/12/4 00:00:00 - 2014/12/4 02:00:00) or (2014/12/4 04:00:00 - 2014/12/4 06:00:00)
machine B can work in following ranges:
(2014/12/4 02:00:00 - 2014/12/4 04:00:00) or (2014/12/4 05:00:00 - 2014/12/4 07:00:00)
Each product must go through machine A and then machine B.
- Each product take some times in each machine (60 minutes in my sample).
- Machine B should be start after machine A finished it's work.
- B can start working, at most 10 minutes after A finished its work. [Updated]
- The goal is to minimize the order production time.
I used following code to convert a DateTime
to minutes:
var minutes = new TimeSpan(dateTime.Ticks).TotalMinutes;
So using above code my DateTime
ranges converted to Double
ranges.
I'm using Microsoft Solver Foundation to solve the problem, so I used following code:
var context = SolverContext.GetContext();
var model = context.CreateModel();
var a_OperationTime = 60;
var b_OperationTime = 60;
var tolerance = 10;
//Decision
Decision A_StartTime = new Decision(Domain.IntegerNonnegative, "A_StartTime");
model.AddDecision(A_StartTime);
Decision B_StartTime = new Decision(Domain.IntegerNonnegative, "B_StartTime");
model.AddDecision(B_StartTime);
//Constraints
model.AddConstraint("A_TimeLimitations" ,
(1059220800 <= A_StartTime <= 1059220860) |
(1059221160 <= A_StartTime <= 1059221220));
model.AddConstraint("B_TimeLimitations" ,
(1059220920 <= B_StartTime <= 1059220980) |
(1059221100 <= B_StartTime <= 1059221160));
model.AddConstraint("B_ContiguousLimitations" ,
B_StartTime - (A_StartTime + 60) <= tolerence);
//Goal
var A_StartTime = model.Decisions.First(x => x.Name == "A_StartTime");
var B_StartTime = model.Decisions.First(x => x.Name == "B_StartTime");
model.AddGoals("OrderDuration", GoalKind.Minimize, B_StartTime - A_StartTime);
//Solve
var directive = new ConstraintProgrammingDirective();
//directive.TimeLimit = 10000;
var solution = context.Solve(directive);
But when I run the code it seems to go into an infinite loop, when I specify TimeLimit
for my directive
, after 10000 milliseconds, solution.Quality
is Unknown
that it means MSF
could not find any solution, if I remove second DateTime
range in machine A
the code can find a solution.
Does anyone know where is the problem?
I found the problems
DateTime
s todouble
converting method with hankank guidanceSo the final solution is here: