本文整理汇总了C#中Solver.MakeSumLessOrEqual方法的典型用法代码示例。如果您正苦于以下问题:C# Solver.MakeSumLessOrEqual方法的具体用法?C# Solver.MakeSumLessOrEqual怎么用?C# Solver.MakeSumLessOrEqual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solver
的用法示例。
在下文中一共展示了Solver.MakeSumLessOrEqual方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Solve
//.........这里部分代码省略.........
}
if (ok)
{
filtered_starts.Add(slot);
}
possible_starts[speaker] = filtered_starts.ToArray();
}
starts[speaker] =
solver.MakeIntVar(possible_starts[speaker], "start[" + speaker + "]");
}
List<IntVar>[] contributions_per_slot =
new List<IntVar>[last_slot + 1];
for (int slot = first_slot; slot <= last_slot; ++slot)
{
contributions_per_slot[slot] = new List<IntVar>();
}
for (int speaker = 0; speaker < number_of_speakers; ++speaker)
{
int duration = durations[speaker];
IntVar start_var = starts[speaker];
foreach (int start in possible_starts[speaker])
{
for (int offset = 0; offset < duration; ++offset)
{
contributions_per_slot[start + offset].Add(start_var.IsEqual(start));
}
}
}
// Force the schedule to be consistent.
for (int slot = first_slot; slot <= last_slot; ++slot)
{
solver.Add(
solver.MakeSumLessOrEqual(contributions_per_slot[slot].ToArray(), 1));
}
// Add minimum start info.
for (int speaker = 0; speaker < number_of_speakers; ++speaker)
{
solver.Add(starts[speaker] >= first_slot);
}
// Creates makespan.
IntVar[] end_times = new IntVar[number_of_speakers];
for (int speaker = 0; speaker < number_of_speakers; speaker++)
{
end_times[speaker] = (starts[speaker] + (durations[speaker] - 1)).Var();
}
IntVar last_slot_var = end_times.Max().VarWithName("last_slot");
// Add trivial bound to objective.
last_slot_var.SetMin(first_slot + sum_of_durations - 1);
// Redundant scheduling constraint.
IntervalVar[] intervals =
solver.MakeFixedDurationIntervalVarArray(starts, durations, "intervals");
DisjunctiveConstraint disjunctive =
solver.MakeDisjunctiveConstraint(intervals, "disjunctive");
solver.Add(disjunctive);
//
// Search
//
List<IntVar> short_talks = new List<IntVar>();
List<IntVar> long_talks = new List<IntVar>();
for (int speaker = 0; speaker < number_of_speakers; ++speaker)