Skip to content

Commit

Permalink
fix3
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Sep 26, 2024
1 parent ad3c36a commit efdec78
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 106 deletions.
9 changes: 5 additions & 4 deletions ortools/sat/go/cpmodel/cp_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,10 +946,11 @@ func (cp *Builder) AddAllowedAssignments(vars ...IntVar) TableConstraint {
// optional events incrementally after construction.
func (cp *Builder) AddReservoirConstraint(min, max int64) ReservoirConstraint {
return ReservoirConstraint{
cp.appendConstraint(&cmpb.ConstraintProto{
Constraint: &cmpb.ConstraintProto_Reservoir{&cmpb.ReservoirConstraintProto{
MinLevel: min, MaxLevel: max,
}}},
cp.appendConstraint(
&cmpb.ConstraintProto{
Constraint: &cmpb.ConstraintProto_Reservoir{&cmpb.ReservoirConstraintProto{
MinLevel: min, MaxLevel: max,
}}},
), cp.NewConstant(1).Index()}
}

Expand Down
201 changes: 99 additions & 102 deletions ortools/sat/go/cpmodel/cp_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,13 +1073,11 @@ func TestCpModelBuilder_Constraints(t *testing.T) {
return m.GetConstraints()[c.Index()]
},
want: &cmpb.ConstraintProto{
Constraint: &cmpb.ConstraintProto_Linear{
&cmpb.LinearConstraintProto{
Vars: []int32{int32(iv1.Index())},
Coeffs: []int64{1},
Domain: []int64{math.MinInt64, 9, 11, math.MaxInt64},
},
},
Constraint: &cmpb.ConstraintProto_Linear{&cmpb.LinearConstraintProto{
Vars: []int32{int32(iv1.Index())},
Coeffs: []int64{1},
Domain: []int64{math.MinInt64, 9, 11, math.MaxInt64},
}},
},
},
{
Expand All @@ -1091,27 +1089,27 @@ func TestCpModelBuilder_Constraints(t *testing.T) {
},
want: &cmpb.ConstraintProto{
Constraint: &cmpb.ConstraintProto_AllDiff{&cmpb.AllDifferentConstraintProto{
Exprs: []*cmpb.LinearExpressionProto{
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv1.Index())},
Coeffs: []int64{1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(bv1.Index())},
Coeffs: []int64{1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(bv2.Index())},
Coeffs: []int64{-1},
Offset: 1,
},
&cmpb.LinearExpressionProto{
Vars: []int32{},
Coeffs: []int64{},
Offset: 10,
},
Exprs: []*cmpb.LinearExpressionProto{
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv1.Index())},
Coeffs: []int64{1},
},
}},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(bv1.Index())},
Coeffs: []int64{1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(bv2.Index())},
Coeffs: []int64{-1},
Offset: 1,
},
&cmpb.LinearExpressionProto{
Vars: []int32{},
Coeffs: []int64{},
Offset: 10,
},
},
}},
},
},
{
Expand All @@ -1123,9 +1121,9 @@ func TestCpModelBuilder_Constraints(t *testing.T) {
},
want: &cmpb.ConstraintProto{
Constraint: &cmpb.ConstraintProto_Element{&cmpb.ElementConstraintProto{
Index: int32(iv1.Index()),
Target: int32(iv4.Index()),
Vars: []int32{int32(iv2.Index()), int32(iv3.Index())},
Index: int32(iv1.Index()),
Target: int32(iv4.Index()),
Vars: []int32{int32(iv2.Index()), int32(iv3.Index())},
}},
},
},
Expand All @@ -1138,13 +1136,13 @@ func TestCpModelBuilder_Constraints(t *testing.T) {
},
want: &cmpb.ConstraintProto{
Constraint: &cmpb.ConstraintProto_Element{&cmpb.ElementConstraintProto{
Index: int32(iv1.Index()),
Target: int32(iv4.Index()),
Vars: []int32{
int32(model.NewConstant(10).Index()),
int32(model.NewConstant(20).Index()),
},
}},
Index: int32(iv1.Index()),
Target: int32(iv4.Index()),
Vars: []int32{
int32(model.NewConstant(10).Index()),
int32(model.NewConstant(20).Index()),
},
}},
},
},
{
Expand All @@ -1156,9 +1154,9 @@ func TestCpModelBuilder_Constraints(t *testing.T) {
},
want: &cmpb.ConstraintProto{
Constraint: &cmpb.ConstraintProto_Inverse{&cmpb.InverseConstraintProto{
FDirect: []int32{int32(iv1.Index()), int32(iv2.Index())},
FInverse: []int32{int32(iv3.Index()), int32(iv4.Index())},
}},
FDirect: []int32{int32(iv1.Index()), int32(iv2.Index())},
FInverse: []int32{int32(iv3.Index()), int32(iv4.Index())},
}},
},
},
{
Expand All @@ -1170,21 +1168,21 @@ func TestCpModelBuilder_Constraints(t *testing.T) {
},
want: &cmpb.ConstraintProto{
Constraint: &cmpb.ConstraintProto_LinMax{&cmpb.LinearArgumentProto{
Target: &cmpb.LinearExpressionProto{
Vars: []int32{int32(iv1.Index())},
Target: &cmpb.LinearExpressionProto{
Vars: []int32{int32(iv1.Index())},
Coeffs: []int64{-1},
},
Exprs: []*cmpb.LinearExpressionProto{
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv2.Index())},
Coeffs: []int64{-1},
},
Exprs: []*cmpb.LinearExpressionProto{
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv2.Index())},
Coeffs: []int64{-1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv3.Index())},
Coeffs: []int64{-1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv3.Index())},
Coeffs: []int64{-1},
},
}},
},
}},
},
},
{
Expand All @@ -1196,21 +1194,21 @@ func TestCpModelBuilder_Constraints(t *testing.T) {
},
want: &cmpb.ConstraintProto{
Constraint: &cmpb.ConstraintProto_LinMax{&cmpb.LinearArgumentProto{
Target: &cmpb.LinearExpressionProto{
Vars: []int32{int32(iv1.Index())},
Target: &cmpb.LinearExpressionProto{
Vars: []int32{int32(iv1.Index())},
Coeffs: []int64{1},
},
Exprs: []*cmpb.LinearExpressionProto{
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv2.Index())},
Coeffs: []int64{1},
},
Exprs: []*cmpb.LinearExpressionProto{
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv2.Index())},
Coeffs: []int64{1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv3.Index())},
Coeffs: []int64{1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv3.Index())},
Coeffs: []int64{1},
},
}},
},
}},
},
},
{
Expand All @@ -1222,21 +1220,21 @@ func TestCpModelBuilder_Constraints(t *testing.T) {
},
want: &cmpb.ConstraintProto{
Constraint: &cmpb.ConstraintProto_IntProd{&cmpb.LinearArgumentProto{
Target: &cmpb.LinearExpressionProto{
Vars: []int32{int32(iv1.Index())},
Target: &cmpb.LinearExpressionProto{
Vars: []int32{int32(iv1.Index())},
Coeffs: []int64{1},
},
Exprs: []*cmpb.LinearExpressionProto{
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv2.Index())},
Coeffs: []int64{1},
},
Exprs: []*cmpb.LinearExpressionProto{
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv2.Index())},
Coeffs: []int64{1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv3.Index())},
Coeffs: []int64{1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv3.Index())},
Coeffs: []int64{1},
},
}},
},
}},
},
},
{
Expand All @@ -1248,21 +1246,21 @@ func TestCpModelBuilder_Constraints(t *testing.T) {
},
want: &cmpb.ConstraintProto{
Constraint: &cmpb.ConstraintProto_IntDiv{&cmpb.LinearArgumentProto{
Target: &cmpb.LinearExpressionProto{
Vars: []int32{int32(iv1.Index())},
Target: &cmpb.LinearExpressionProto{
Vars: []int32{int32(iv1.Index())},
Coeffs: []int64{1},
},
Exprs: []*cmpb.LinearExpressionProto{
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv2.Index())},
Coeffs: []int64{1},
},
Exprs: []*cmpb.LinearExpressionProto{
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv2.Index())},
Coeffs: []int64{1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv3.Index())},
Coeffs: []int64{1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv3.Index())},
Coeffs: []int64{1},
},
}},
},
}},
},
},
{
Expand All @@ -1274,21 +1272,21 @@ func TestCpModelBuilder_Constraints(t *testing.T) {
},
want: &cmpb.ConstraintProto{
Constraint: &cmpb.ConstraintProto_LinMax{&cmpb.LinearArgumentProto{
Target: &cmpb.LinearExpressionProto{
Vars: []int32{int32(iv1.Index())},
Target: &cmpb.LinearExpressionProto{
Vars: []int32{int32(iv1.Index())},
Coeffs: []int64{1},
},
Exprs: []*cmpb.LinearExpressionProto{
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv2.Index())},
Coeffs: []int64{1},
},
Exprs: []*cmpb.LinearExpressionProto{
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv2.Index())},
Coeffs: []int64{1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv2.Index())},
Coeffs: []int64{-1},
},
&cmpb.LinearExpressionProto{
Vars: []int32{int32(iv2.Index())},
Coeffs: []int64{-1},
},
}},
},
}},
},
},
{
Expand Down Expand Up @@ -1418,8 +1416,7 @@ func TestCpModelBuilder_Constraints(t *testing.T) {
},
},
ActiveLiterals: []int32{int32(one.Index())},
},
},
}},
},
},
{
Expand Down

0 comments on commit efdec78

Please sign in to comment.