本文整理汇总了C#中Solver.MakeFixedDurationIntervalVar方法的典型用法代码示例。如果您正苦于以下问题:C# Solver.MakeFixedDurationIntervalVar方法的具体用法?C# Solver.MakeFixedDurationIntervalVar怎么用?C# Solver.MakeFixedDurationIntervalVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solver
的用法示例。
在下文中一共展示了Solver.MakeFixedDurationIntervalVar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Solve
/**
*
* Moving furnitures (scheduling) problem in Google CP Solver.
*
* Marriott & Stukey: 'Programming with constraints', page 112f
*
* Also see http://www.hakank.org/or-tools/furniture_moving.py
*
*/
private static void Solve()
{
Solver solver = new Solver("FurnitureMovingIntervals");
const int n = 4;
int[] durations = {30,10,15,15};
int[] demand = {3, 1, 3, 2};
const int upper_limit = 160;
const int max_num_workers = 5;
//
// Decision variables
//
IntervalVar[] tasks = new IntervalVar[n];
for (int i = 0; i < n; ++i)
{
tasks[i] = solver.MakeFixedDurationIntervalVar(0,
upper_limit - durations[i],
durations[i],
false,
"task_" + i);
}
// Fillers that span the whole resource and limit the available
// number of workers.
IntervalVar[] fillers = new IntervalVar[max_num_workers];
for (int i = 0; i < max_num_workers; ++i)
{
fillers[i] = solver.MakeFixedDurationIntervalVar(0,
0,
upper_limit,
true,
"filler_" + i);
}
// Number of needed resources, to be minimized or constrained.
IntVar num_workers = solver.MakeIntVar(0, max_num_workers, "num_workers");
// Links fillers and num_workers.
for (int i = 0; i < max_num_workers; ++i)
{
solver.Add((num_workers > i) + fillers[i].PerformedExpr() == 1);
}
// Creates makespan.
IntVar[] ends = new IntVar[n];
for (int i = 0; i < n; ++i)
{
ends[i] = tasks[i].EndExpr().Var();
}
IntVar end_time = ends.Max().VarWithName("end_time");
//
// Constraints
//
IntervalVar[] all_tasks = new IntervalVar[n + max_num_workers];
int[] all_demands = new int[n + max_num_workers];
for (int i = 0; i < n; ++i)
{
all_tasks[i] = tasks[i];
all_demands[i] = demand[i];
}
for (int i = 0; i < max_num_workers; ++i)
{
all_tasks[i + n] = fillers[i];
all_demands[i + n] = 1;
}
solver.Add(all_tasks.Cumulative(all_demands, max_num_workers, "workers"));
//
// Some extra constraints to play with
//
// all tasks must end within an hour
// solver.Add(end_time <= 60);
// All tasks should start at time 0
// for(int i = 0; i < n; i++) {
// solver.Add(tasks[i].StartAt(0));
// }
// limitation of the number of people
// solver.Add(num_workers <= 3);
solver.Add(num_workers <= 4);
//
// Objective
//
// OptimizeVar obj = num_workers.Minimize(1);
OptimizeVar obj = end_time.Minimize(1);
//.........这里部分代码省略.........