Skip to content

Commit

Permalink
[CP-SAT] c# fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Aug 16, 2024
1 parent 1b9e132 commit 43e28c4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ortools/sat/csharp/CpModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,11 @@ public ReservoirConstraint AddReservoirConstraint(long minLevel, long maxLevel)
return ct;
}

/**
* <summary>
* Adds <c>var == i + offset ⇔ bool_vars[i] == true for all i</c>.
* </summary>
*/
public void AddMapDomain(IntVar var, IEnumerable<IntVar> bool_vars, long offset = 0)
{
int i = 0;
Expand All @@ -523,11 +528,11 @@ public void AddMapDomain(IntVar var, IEnumerable<IntVar> bool_vars, long offset
model_.Constraints.Add(ct1);

LinearConstraintProto lin2 = new LinearConstraintProto();
lin1.Vars.Capacity = 1;
lin2.Vars.Capacity = 1;
lin2.Vars.Add(var_index);
lin1.Coeffs.Capacity = 1;
lin2.Coeffs.Capacity = 1;
lin2.Coeffs.Add(1L);
lin1.Domain.Capacity = 4;
lin2.Domain.Capacity = 4;
lin2.Domain.Add(Int64.MinValue);
lin2.Domain.Add(offset + i - 1);
lin2.Domain.Add(offset + i + 1);
Expand Down Expand Up @@ -1057,7 +1062,7 @@ public void AddHint(ILiteral lit, bool value)
model_.SolutionHint.Vars.Add(Negated(index));
model_.SolutionHint.Values.Add(value ? 0 : 1);
}
}
}

/** <summary>Clears all hinting from the model.</summary>*/
public void ClearHints()
Expand Down

0 comments on commit 43e28c4

Please sign in to comment.