本文整理汇总了C#中IntVar.Transition方法的典型用法代码示例。如果您正苦于以下问题:C# IntVar.Transition方法的具体用法?C# IntVar.Transition怎么用?C# IntVar.Transition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IntVar
的用法示例。
在下文中一共展示了IntVar.Transition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MyContiguity
static void MyContiguity(Solver solver, IntVar[] x) {
// the DFA (for regular)
int initial_state = 1;
// all states are accepting states
int[] accepting_states = {1,2,3};
// The regular expression 0*1*0* {state, input, next state}
int[,] transition_tuples = { {1, 0, 1},
{1, 1, 2},
{2, 0, 3},
{2, 1, 2},
{3, 0, 3} };
IntTupleSet result = new IntTupleSet(3);
result.InsertAll(transition_tuples);
solver.Add(x.Transition(result,
initial_state,
accepting_states));
}
示例2: Solve
//.........这里部分代码省略.........
//
// For TransitionConstraint
//
IntVar[,] x =
solver.MakeIntVarMatrix(num_nurses, num_days, valid_shifts, "x");
IntVar[] x_flat = x.Flatten();
//
// summary of the nurses
//
IntVar[] nurse_stat = new IntVar[num_nurses];
//
// summary of the shifts per day
//
int num_shifts = shifts.Length;
IntVar[,] day_stat = new IntVar[num_days, num_shifts];
for(int i = 0; i < num_days; i++) {
for(int j = 0; j < num_shifts; j++) {
day_stat[i,j] = solver.MakeIntVar(0, num_nurses, "day_stat");
}
}
//
// Constraints
//
for(int i = 0; i < num_nurses; i++) {
IntVar[] reg_input = new IntVar[num_days];
for(int j = 0; j < num_days; j++) {
reg_input[j] = x[i,j];
}
solver.Add(reg_input.Transition(transition_tuples,
initial_state,
accepting_states));
}
//
// Statistics and constraints for each nurse
//
for(int nurse = 0; nurse < num_nurses; nurse++) {
// Number of worked days (either day or night shift)
IntVar[] nurse_days = new IntVar[num_days];
for(int day = 0; day < num_days; day++) {
nurse_days[day] =
x[nurse, day].IsMember(new int[] { day_shift, night_shift });
}
nurse_stat[nurse] = nurse_days.Sum().Var();
// Each nurse must work between 7 and 10
// days/nights during this period
solver.Add(nurse_stat[nurse] >= 7 * week_multiplier / nurse_multiplier);
solver.Add(nurse_stat[nurse] <= 10 * week_multiplier / nurse_multiplier);
}
//
// Statistics and constraints for each day
//
for(int day = 0; day < num_days; day++) {
IntVar[] nurses = new IntVar[num_nurses];
for(int nurse = 0; nurse < num_nurses; nurse++) {
nurses[nurse] = x[nurse, day];
}