当前位置: 首页>>代码示例>>C#>>正文


C# Solver.MakeSumLessOrEqual方法代码示例

本文整理汇总了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)
开发者ID:RickOne16,项目名称:or-tools,代码行数:67,代码来源:techtalk_scheduling.cs


注:本文中的Solver.MakeSumLessOrEqual方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。