Skip to content

Commit

Permalink
Merge pull request #4347 from CADBIMDeveloper/net-add-map-domain-fixes
Browse files Browse the repository at this point in the history
.net CpModel.AddMapDomain: add method summary and tiny fixes
  • Loading branch information
lperron authored Aug 15, 2024
2 parents d4a5890 + 210f36e commit 056cc98
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 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

0 comments on commit 056cc98

Please sign in to comment.