diff --git a/ortools/sat/cp_model.proto b/ortools/sat/cp_model.proto index b76dc95aa1a..b57d2056ba1 100644 --- a/ortools/sat/cp_model.proto +++ b/ortools/sat/cp_model.proto @@ -18,6 +18,7 @@ syntax = "proto3"; package operations_research.sat; option csharp_namespace = "Google.OrTools.Sat"; +option go_package = "github.com/google/or-tools/ortools/sat/proto/cpmodel"; option java_package = "com.google.ortools.sat"; option java_multiple_files = true; option java_outer_classname = "CpModelProtobuf"; diff --git a/ortools/sat/docs/README.md b/ortools/sat/docs/README.md index c00f1d65a52..82df9dec24d 100644 --- a/ortools/sat/docs/README.md +++ b/ortools/sat/docs/README.md @@ -226,8 +226,8 @@ package main import ( "fmt" - "github.com/golang/glog" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" "ortools/sat/go/cpmodel" ) @@ -264,7 +264,7 @@ func simpleSatProgram() error { func main() { if err := simpleSatProgram(); err != nil { - glog.Exitf("simpleSatProgram returned with error: %v", err) + log.Exitf("simpleSatProgram returned with error: %v", err) } } ``` diff --git a/ortools/sat/docs/boolean_logic.md b/ortools/sat/docs/boolean_logic.md index 9f0d10c8fba..db47873d847 100644 --- a/ortools/sat/docs/boolean_logic.md +++ b/ortools/sat/docs/boolean_logic.md @@ -113,7 +113,7 @@ public class LiteralSampleSat package main import ( - "github.com/golang/glog" + log "github.com/golang/glog" "ortools/sat/go/cpmodel" ) @@ -123,7 +123,7 @@ func literalSampleSat() { x := model.NewBoolVar().WithName("x") notX := x.Not() - glog.Infof("x = %d, x.Not() = %d", x.Index(), notX.Index()) + log.Infof("x = %d, x.Not() = %d", x.Index(), notX.Index()) } func main() { @@ -525,10 +525,10 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" + log "github.com/golang/glog" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) func booleanProductSample() error { @@ -576,7 +576,7 @@ func booleanProductSample() error { func main() { err := booleanProductSample() if err != nil { - glog.Exitf("booleanProductSample returned with error: %v", err) + log.Exitf("booleanProductSample returned with error: %v", err) } } ``` diff --git a/ortools/sat/docs/channeling.md b/ortools/sat/docs/channeling.md index cf16b8960d2..f4811905ff9 100644 --- a/ortools/sat/docs/channeling.md +++ b/ortools/sat/docs/channeling.md @@ -308,11 +308,11 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) func channelingSampleSat() error { @@ -367,7 +367,7 @@ func channelingSampleSat() error { func main() { if err := channelingSampleSat(); err != nil { - glog.Exitf("channelingSampleSat returned with error: %v", err) + log.Exitf("channelingSampleSat returned with error: %v", err) } } ``` @@ -895,7 +895,7 @@ package main import ( "fmt" - "github.com/golang/glog" + log "github.com/golang/glog" "ortools/sat/go/cpmodel" ) @@ -907,7 +907,7 @@ const ( ) type item struct { - Cost, Copies int64_t + Cost, Copies int64 } func binpackingProblemSat() error { @@ -993,7 +993,7 @@ func binpackingProblemSat() error { func main() { if err := binpackingProblemSat(); err != nil { - glog.Exitf("binpackingProblemSat returned with error: %v", err) + log.Exitf("binpackingProblemSat returned with error: %v", err) } } ``` diff --git a/ortools/sat/docs/integer_arithmetic.md b/ortools/sat/docs/integer_arithmetic.md index 2fcd3c5629b..1a7e0e3aacd 100644 --- a/ortools/sat/docs/integer_arithmetic.md +++ b/ortools/sat/docs/integer_arithmetic.md @@ -275,8 +275,8 @@ package main import ( "fmt" - "github.com/golang/glog" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" "ortools/sat/go/cpmodel" ) @@ -315,7 +315,7 @@ func rabbitsAndPheasants() error { func main() { if err := rabbitsAndPheasants(); err != nil { - glog.Exitf("rabbitsAndPheasants returned with error: %v", err) + log.Exitf("rabbitsAndPheasants returned with error: %v", err) } } ``` @@ -675,11 +675,11 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) const ( @@ -742,7 +742,7 @@ func earlinessTardinessCostSampleSat() error { func main() { if err := earlinessTardinessCostSampleSat(); err != nil { - glog.Exitf("earlinessTardinessCostSampleSat returned with error: %v", err) + log.Exitf("earlinessTardinessCostSampleSat returned with error: %v", err) } } ``` @@ -1131,11 +1131,11 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) func stepFunctionSampleSat() error { @@ -1208,7 +1208,7 @@ func stepFunctionSampleSat() error { func main() { if err := stepFunctionSampleSat(); err != nil { - glog.Exitf("stepFunctionSampleSat returned with error: %v", err) + log.Exitf("stepFunctionSampleSat returned with error: %v", err) } } ``` diff --git a/ortools/sat/docs/model.md b/ortools/sat/docs/model.md index 3949f8ce2bc..2218611998a 100644 --- a/ortools/sat/docs/model.md +++ b/ortools/sat/docs/model.md @@ -310,8 +310,8 @@ package main import ( "fmt" - "github.com/golang/glog" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" "ortools/sat/go/cpmodel" ) @@ -353,7 +353,7 @@ func solutionHintingSampleSat() error { func main() { if err := solutionHintingSampleSat(); err != nil { - glog.Exitf("solutionHintingSampleSat returned with error: %v", err) + log.Exitf("solutionHintingSampleSat returned with error: %v", err) } } ``` diff --git a/ortools/sat/docs/scheduling.md b/ortools/sat/docs/scheduling.md index 19a8b5264c9..00aacda1860 100644 --- a/ortools/sat/docs/scheduling.md +++ b/ortools/sat/docs/scheduling.md @@ -195,7 +195,7 @@ package main import ( "fmt" - "github.com/golang/glog" + log "github.com/golang/glog" "ortools/sat/go/cpmodel" ) @@ -231,7 +231,7 @@ func intervalSampleSat() error { func main() { if err := intervalSampleSat(); err != nil { - glog.Exitf("intervalSampleSat returned with error: %v", err) + log.Exitf("intervalSampleSat returned with error: %v", err) } } ``` @@ -421,7 +421,7 @@ package main import ( "fmt" - "github.com/golang/glog" + log "github.com/golang/glog" "ortools/sat/go/cpmodel" ) @@ -454,7 +454,7 @@ func optionalIntervalSampleSat() error { func main() { if err := optionalIntervalSampleSat(); err != nil { - glog.Exitf("optionalIntervalSampleSat returned with error: %v", err) + log.Exitf("optionalIntervalSampleSat returned with error: %v", err) } } ``` @@ -841,8 +841,8 @@ package main import ( "fmt" - "github.com/golang/glog" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" "ortools/sat/go/cpmodel" ) @@ -909,7 +909,7 @@ func noOverlapSampleSat() error { func main() { if err := noOverlapSampleSat(); err != nil { - glog.Exitf("noOverlapSampleSat returned with error: %v", err) + log.Exitf("noOverlapSampleSat returned with error: %v", err) } } ``` @@ -1865,8 +1865,8 @@ package main import ( "fmt" - "github.com/golang/glog" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" "ortools/sat/go/cpmodel" ) @@ -1937,7 +1937,7 @@ func rankingSampleSat() error { for t := 0; t < numTasks; t++ { start := model.NewIntVarFromDomain(horizon) - duration := cpmodel.NewConstant(int64_t(t + 1)) + duration := cpmodel.NewConstant(int64(t + 1)) end := model.NewIntVarFromDomain(horizon) var presence cpmodel.BoolVar if t < numTasks/2 { @@ -2008,7 +2008,7 @@ func rankingSampleSat() error { func main() { if err := rankingSampleSat(); err != nil { - glog.Exitf("rankingSampleSat returned with error: %v", err) + log.Exitf("rankingSampleSat returned with error: %v", err) } } ``` diff --git a/ortools/sat/docs/solver.md b/ortools/sat/docs/solver.md index 5881234d438..6feee57dde1 100644 --- a/ortools/sat/docs/solver.md +++ b/ortools/sat/docs/solver.md @@ -194,11 +194,11 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) func solveWithTimeLimitSampleSat() error { @@ -240,7 +240,7 @@ func solveWithTimeLimitSampleSat() error { func main() { if err := solveWithTimeLimitSampleSat(); err != nil { - glog.Exitf("solveWithTimeLimitSampleSat returned with error: %v", err) + log.Exitf("solveWithTimeLimitSampleSat returned with error: %v", err) } } ``` @@ -535,10 +535,10 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" + log "github.com/golang/glog" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) func solveAndPrintIntermediateSolutionsSampleSat() error { @@ -583,7 +583,7 @@ func solveAndPrintIntermediateSolutionsSampleSat() error { func main() { if err := solveAndPrintIntermediateSolutionsSampleSat(); err != nil { - glog.Exitf("solveAndPrintIntermediateSolutionsSampleSat returned with error: %v", err) + log.Exitf("solveAndPrintIntermediateSolutionsSampleSat returned with error: %v", err) } } ``` @@ -872,10 +872,10 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" + log "github.com/golang/glog" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) func searchForAllSolutionsSampleSat() error { @@ -917,7 +917,7 @@ func searchForAllSolutionsSampleSat() error { func main() { if err := searchForAllSolutionsSampleSat(); err != nil { - glog.Exitf("searchForAllSolutionsSampleSat returned with error: %v", err) + log.Exitf("searchForAllSolutionsSampleSat returned with error: %v", err) } } ``` diff --git a/ortools/sat/go/cpmodel/BUILD.bazel b/ortools/sat/go/cpmodel/BUILD.bazel index 707ce53b2f3..25b32f8db7f 100644 --- a/ortools/sat/go/cpmodel/BUILD.bazel +++ b/ortools/sat/go/cpmodel/BUILD.bazel @@ -18,8 +18,8 @@ go_library( srcs = [ "cp_model.go", "cp_solver.go", - "cp_solver_c.cc", - "cp_solver_c.h", + #"cp_solver_c.cc", + #"cp_solver_c.h", "domain.go", ], cdeps = [":cp_solver_c"], @@ -57,12 +57,12 @@ cc_library( srcs = ["cp_solver_c.cc"], hdrs = ["cp_solver_c.h"], deps = [ + "//ortools/base:memutil", "//ortools/sat:cp_model_cc_proto", "//ortools/sat:cp_model_solver", + "//ortools/sat:model", "//ortools/sat:sat_parameters_cc_proto", "//ortools/util:time_limit", - "@com_google_absl//absl/log", - "@com_google_absl//absl/status", - "@com_google_absl//absl/strings", + "@com_google_absl//absl/log:check", ], ) diff --git a/ortools/sat/go/cpmodel/cp_model.go b/ortools/sat/go/cpmodel/cp_model.go index 1822f6c55fa..561233aece8 100644 --- a/ortools/sat/go/cpmodel/cp_model.go +++ b/ortools/sat/go/cpmodel/cp_model.go @@ -578,8 +578,8 @@ func (cp *Builder) NewOptionalIntervalVar(start, size, end LinearArgument, prese Start: start.asLinearExpressionProto(), Size: size.asLinearExpressionProto(), End: end.asLinearExpressionProto(), - }, - }}) + }}, + }) return IntervalVar{cpb: cp, ind: ind} } @@ -803,11 +803,10 @@ func (cp *Builder) AddMinEquality(target LinearArgument, exprs ...LinearArgument } return cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_LinMax{ - &cmpb.LinearArgumentProto{ - Target: asNegatedLinearExpressionProto(target), - Exprs: protos, - }}, + Constraint: &cmpb.ConstraintProto_LinMax{&cmpb.LinearArgumentProto{ + Target: asNegatedLinearExpressionProto(target), + Exprs: protos, + }}, }) } @@ -819,11 +818,10 @@ func (cp *Builder) AddMaxEquality(target LinearArgument, exprs ...LinearArgument } return cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_LinMax{ - &cmpb.LinearArgumentProto{ - Target: target.asLinearExpressionProto(), - Exprs: protos, - }}, + Constraint: &cmpb.ConstraintProto_LinMax{&cmpb.LinearArgumentProto{ + Target: target.asLinearExpressionProto(), + Exprs: protos, + }}, }) } @@ -835,53 +833,49 @@ func (cp *Builder) AddMultiplicationEquality(target LinearArgument, exprs ...Lin } return cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_IntProd{ - &cmpb.LinearArgumentProto{ - Target: target.asLinearExpressionProto(), - Exprs: protos, - }}, + Constraint: &cmpb.ConstraintProto_IntProd{&cmpb.LinearArgumentProto{ + Target: target.asLinearExpressionProto(), + Exprs: protos, + }}, }) } // AddDivisionEquality adds the constraint: target == num / denom. func (cp *Builder) AddDivisionEquality(target, num, denom LinearArgument) Constraint { return cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_IntDiv{ - &cmpb.LinearArgumentProto{ - Target: target.asLinearExpressionProto(), - Exprs: []*cmpb.LinearExpressionProto{ - num.asLinearExpressionProto(), - denom.asLinearExpressionProto(), - }, - }}, + Constraint: &cmpb.ConstraintProto_IntDiv{&cmpb.LinearArgumentProto{ + Target: target.asLinearExpressionProto(), + Exprs: []*cmpb.LinearExpressionProto{ + num.asLinearExpressionProto(), + denom.asLinearExpressionProto(), + }, + }}, }) } // AddAbsEquality adds the constraint: target == Abs(expr). func (cp *Builder) AddAbsEquality(target, expr LinearArgument) Constraint { return cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_LinMax{ - &cmpb.LinearArgumentProto{ - Target: target.asLinearExpressionProto(), - Exprs: []*cmpb.LinearExpressionProto{ - expr.asLinearExpressionProto(), - asNegatedLinearExpressionProto(expr), - }, - }}, + Constraint: &cmpb.ConstraintProto_LinMax{&cmpb.LinearArgumentProto{ + Target: target.asLinearExpressionProto(), + Exprs: []*cmpb.LinearExpressionProto{ + expr.asLinearExpressionProto(), + asNegatedLinearExpressionProto(expr), + }, + }}, }) } // AddModuloEquality adds the constraint: target == v % mod. func (cp *Builder) AddModuloEquality(target, v, mod LinearArgument) Constraint { return cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_IntMod{ - &cmpb.LinearArgumentProto{ - Target: target.asLinearExpressionProto(), - Exprs: []*cmpb.LinearExpressionProto{ - v.asLinearExpressionProto(), - mod.asLinearExpressionProto(), - }, - }}, + Constraint: &cmpb.ConstraintProto_IntMod{&cmpb.LinearArgumentProto{ + Target: target.asLinearExpressionProto(), + Exprs: []*cmpb.LinearExpressionProto{ + v.asLinearExpressionProto(), + mod.asLinearExpressionProto(), + }, + }}, }) } @@ -894,37 +888,33 @@ func (cp *Builder) AddNoOverlap(vars ...IntervalVar) Constraint { } return cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_NoOverlap{ - &cmpb.NoOverlapConstraintProto{ - Intervals: intervals, - }}, + Constraint: &cmpb.ConstraintProto_NoOverlap{&cmpb.NoOverlapConstraintProto{ + Intervals: intervals, + }}, }) } // AddNoOverlap2D adds a no_overlap2D constraint that prevents a set of boxes from overlapping. func (cp *Builder) AddNoOverlap2D() NoOverlap2DConstraint { return NoOverlap2DConstraint{cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_NoOverlap_2D{ - &cmpb.NoOverlap2DConstraintProto{}, - }})} + Constraint: &cmpb.ConstraintProto_NoOverlap_2D{&cmpb.NoOverlap2DConstraintProto{}}, + })} } // AddCircuitConstraint adds a circuit constraint to the model. The circuit constraint is // defined on a graph where the arcs are present if the corresponding literals are set to true. func (cp *Builder) AddCircuitConstraint() CircuitConstraint { return CircuitConstraint{cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_Circuit{ - &cmpb.CircuitConstraintProto{}, - }})} + Constraint: &cmpb.ConstraintProto_Circuit{&cmpb.CircuitConstraintProto{}}, + })} } // AddMultipleCircuitConstraint adds a multiple circuit constraint to the model, aka the "VRP" // (Vehicle Routing Problem) constraint. func (cp *Builder) AddMultipleCircuitConstraint() MultipleCircuitConstraint { return MultipleCircuitConstraint{cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_Routes{ - &cmpb.RoutesConstraintProto{}, - }})} + Constraint: &cmpb.ConstraintProto_Routes{&cmpb.RoutesConstraintProto{}}, + })} } // AddAllowedAssignments adds an allowed assignments constraint to the model. When all variables @@ -937,9 +927,8 @@ func (cp *Builder) AddAllowedAssignments(vars ...IntVar) TableConstraint { } return TableConstraint{cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_Table{ - &cmpb.TableConstraintProto{Vars: varsInd}, - }})} + Constraint: &cmpb.ConstraintProto_Table{&cmpb.TableConstraintProto{Vars: varsInd}}, + })} } // AddReservoirConstraint adds a reservoir constraint with optional refill/emptying events. @@ -951,8 +940,7 @@ func (cp *Builder) AddAllowedAssignments(vars ...IntVar) TableConstraint { // is assigned a value t, then the level of the reservoir changes by // level_change (which is constant) at time t. Therefore, at any time t: // -// sum(level_changes[i] * actives[i] if times[i] <= t) -// in [min_level, max_level] +// sum(level_changes[i] * actives[i] if times[i] <= t) in [min_level, max_level] // // Note that min level must be <= 0, and the max level must be >= 0. // Please use fixed level_changes to simulate an initial state. @@ -963,10 +951,9 @@ func (cp *Builder) AddReservoirConstraint(min, max int64) ReservoirConstraint { return ReservoirConstraint{ cp.appendConstraint( &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_Reservoir{ - &cmpb.ReservoirConstraintProto{ - MinLevel: min, MaxLevel: max, - }}}, + Constraint: &cmpb.ConstraintProto_Reservoir{&cmpb.ReservoirConstraintProto{ + MinLevel: min, MaxLevel: max, + }}}, ), cp.NewConstant(1).Index()} } @@ -1001,12 +988,11 @@ func (cp *Builder) AddAutomaton(transitionVars []IntVar, startState int64, final transitions = append(transitions, int32(v.Index())) } return AutomatonConstraint{cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_Automaton{ - &cmpb.AutomatonConstraintProto{ - Vars: transitions, - StartingState: startState, - FinalStates: finalStates, - }}, + Constraint: &cmpb.ConstraintProto_Automaton{&cmpb.AutomatonConstraintProto{ + Vars: transitions, + StartingState: startState, + FinalStates: finalStates, + }}, })} } @@ -1015,11 +1001,10 @@ func (cp *Builder) AddAutomaton(transitionVars []IntVar, startState int64, final // capacity. func (cp *Builder) AddCumulative(capacity LinearArgument) CumulativeConstraint { return CumulativeConstraint{cp.appendConstraint(&cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_Cumulative{ - &cmpb.CumulativeConstraintProto{ - Capacity: capacity.asLinearExpressionProto(), - }, - }})} + Constraint: &cmpb.ConstraintProto_Cumulative{&cmpb.CumulativeConstraintProto{ + Capacity: capacity.asLinearExpressionProto(), + }}, + })} } // Minimize adds a linear minimization objective. diff --git a/ortools/sat/go/cpmodel/cp_model_test.go b/ortools/sat/go/cpmodel/cp_model_test.go index ad91fefff05..8fa8c53bc07 100644 --- a/ortools/sat/go/cpmodel/cp_model_test.go +++ b/ortools/sat/go/cpmodel/cp_model_test.go @@ -20,11 +20,10 @@ import ( "sort" "testing" - "github.com/google/go-cmp/cmp" - "google.golang.org/protobuf/testing/protocmp" - log "github.com/golang/glog" + "github.com/google/go-cmp/cmp" cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" + "google.golang.org/protobuf/testing/protocmp" ) func Example() { @@ -735,19 +734,17 @@ func TestIntervalVar(t *testing.T) { }, want: &cmpb.ConstraintProto{ EnforcementLiteral: []int32{int32(trueVar.Index())}, - Constraint: &cmpb.ConstraintProto_Interval{ - &cmpb.IntervalConstraintProto{ - Start: &cmpb.LinearExpressionProto{Offset: 1}, - Size: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, - Coeffs: []int64{1}, - }, - End: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv2.Index())}, - Coeffs: []int64{1}, - }, + Constraint: &cmpb.ConstraintProto_Interval{&cmpb.IntervalConstraintProto{ + Start: &cmpb.LinearExpressionProto{Offset: 1}, + Size: &cmpb.LinearExpressionProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{1}, }, - }, + End: &cmpb.LinearExpressionProto{ + Vars: []int32{int32(iv2.Index())}, + Coeffs: []int64{1}, + }, + }}, }, }, { @@ -759,20 +756,18 @@ func TestIntervalVar(t *testing.T) { }, want: &cmpb.ConstraintProto{ EnforcementLiteral: []int32{int32(trueVar.Index())}, - Constraint: &cmpb.ConstraintProto_Interval{ - &cmpb.IntervalConstraintProto{ - Start: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, - Coeffs: []int64{1}, - }, - Size: &cmpb.LinearExpressionProto{Offset: 5}, - End: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, - Coeffs: []int64{1}, - Offset: 5, - }, + Constraint: &cmpb.ConstraintProto_Interval{&cmpb.IntervalConstraintProto{ + Start: &cmpb.LinearExpressionProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{1}, }, - }, + Size: &cmpb.LinearExpressionProto{Offset: 5}, + End: &cmpb.LinearExpressionProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{1}, + Offset: 5, + }, + }}, }, }, { @@ -784,19 +779,17 @@ func TestIntervalVar(t *testing.T) { }, want: &cmpb.ConstraintProto{ EnforcementLiteral: []int32{int32(bv1.Index())}, - Constraint: &cmpb.ConstraintProto_Interval{ - &cmpb.IntervalConstraintProto{ - Start: &cmpb.LinearExpressionProto{Offset: 1}, - Size: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, - Coeffs: []int64{1}, - }, - End: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv2.Index())}, - Coeffs: []int64{1}, - }, + Constraint: &cmpb.ConstraintProto_Interval{&cmpb.IntervalConstraintProto{ + Start: &cmpb.LinearExpressionProto{Offset: 1}, + Size: &cmpb.LinearExpressionProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{1}, }, - }, + End: &cmpb.LinearExpressionProto{ + Vars: []int32{int32(iv2.Index())}, + Coeffs: []int64{1}, + }, + }}, }, }, { @@ -808,20 +801,18 @@ func TestIntervalVar(t *testing.T) { }, want: &cmpb.ConstraintProto{ EnforcementLiteral: []int32{int32(bv1.Index())}, - Constraint: &cmpb.ConstraintProto_Interval{ - &cmpb.IntervalConstraintProto{ - Start: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, - Coeffs: []int64{1}, - }, - Size: &cmpb.LinearExpressionProto{Offset: 5}, - End: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, - Coeffs: []int64{1}, - Offset: 5, - }, + Constraint: &cmpb.ConstraintProto_Interval{&cmpb.IntervalConstraintProto{ + Start: &cmpb.LinearExpressionProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{1}, }, - }, + Size: &cmpb.LinearExpressionProto{Offset: 5}, + End: &cmpb.LinearExpressionProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{1}, + Offset: 5, + }, + }}, }, }, } @@ -880,11 +871,9 @@ func TestCpModelBuilder_Constraints(t *testing.T) { }, want: &cmpb.ConstraintProto{ EnforcementLiteral: []int32{int32(bv3.Index())}, - Constraint: &cmpb.ConstraintProto_BoolOr{ - &cmpb.BoolArgumentProto{ - Literals: []int32{int32(bv1.Index()), int32(bv2.Not().Index())}, - }, - }, + Constraint: &cmpb.ConstraintProto_BoolOr{&cmpb.BoolArgumentProto{ + Literals: []int32{int32(bv1.Index()), int32(bv2.Not().Index())}, + }}, }, }, { @@ -896,11 +885,9 @@ func TestCpModelBuilder_Constraints(t *testing.T) { }, want: &cmpb.ConstraintProto{ EnforcementLiteral: []int32{int32(bv3.Index())}, - Constraint: &cmpb.ConstraintProto_BoolAnd{ - &cmpb.BoolArgumentProto{ - Literals: []int32{int32(bv1.Index()), int32(bv2.Not().Index())}, - }, - }, + Constraint: &cmpb.ConstraintProto_BoolAnd{&cmpb.BoolArgumentProto{ + Literals: []int32{int32(bv1.Index()), int32(bv2.Not().Index())}, + }}, }, }, { @@ -912,11 +899,9 @@ func TestCpModelBuilder_Constraints(t *testing.T) { }, want: &cmpb.ConstraintProto{ EnforcementLiteral: []int32{int32(bv3.Index())}, - Constraint: &cmpb.ConstraintProto_BoolXor{ - &cmpb.BoolArgumentProto{ - Literals: []int32{int32(bv1.Index()), int32(bv2.Not().Index())}, - }, - }, + Constraint: &cmpb.ConstraintProto_BoolXor{&cmpb.BoolArgumentProto{ + Literals: []int32{int32(bv1.Index()), int32(bv2.Not().Index())}, + }}, }, }, { @@ -928,11 +913,9 @@ func TestCpModelBuilder_Constraints(t *testing.T) { }, want: &cmpb.ConstraintProto{ EnforcementLiteral: []int32{int32(bv3.Index())}, - Constraint: &cmpb.ConstraintProto_BoolOr{ - &cmpb.BoolArgumentProto{ - Literals: []int32{int32(bv1.Index()), int32(bv2.Not().Index())}, - }, - }, + Constraint: &cmpb.ConstraintProto_BoolOr{&cmpb.BoolArgumentProto{ + Literals: []int32{int32(bv1.Index()), int32(bv2.Not().Index())}, + }}, }, }, { @@ -944,11 +927,9 @@ func TestCpModelBuilder_Constraints(t *testing.T) { }, want: &cmpb.ConstraintProto{ EnforcementLiteral: []int32{int32(bv3.Index())}, - Constraint: &cmpb.ConstraintProto_AtMostOne{ - &cmpb.BoolArgumentProto{ - Literals: []int32{int32(bv1.Index()), int32(bv2.Not().Index())}, - }, - }, + Constraint: &cmpb.ConstraintProto_AtMostOne{&cmpb.BoolArgumentProto{ + Literals: []int32{int32(bv1.Index()), int32(bv2.Not().Index())}, + }}, }, }, { @@ -960,11 +941,9 @@ func TestCpModelBuilder_Constraints(t *testing.T) { }, want: &cmpb.ConstraintProto{ EnforcementLiteral: []int32{int32(bv3.Index())}, - Constraint: &cmpb.ConstraintProto_ExactlyOne{ - &cmpb.BoolArgumentProto{ - Literals: []int32{int32(bv1.Index()), int32(bv2.Not().Index())}, - }, - }, + Constraint: &cmpb.ConstraintProto_ExactlyOne{&cmpb.BoolArgumentProto{ + Literals: []int32{int32(bv1.Index()), int32(bv2.Not().Index())}, + }}, }, }, { @@ -975,11 +954,9 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_BoolOr{ - &cmpb.BoolArgumentProto{ - Literals: []int32{int32(bv1.Not().Index()), int32(bv2.Not().Index())}, - }, - }, + Constraint: &cmpb.ConstraintProto_BoolOr{&cmpb.BoolArgumentProto{ + Literals: []int32{int32(bv1.Not().Index()), int32(bv2.Not().Index())}, + }}, }, }, { @@ -991,13 +968,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()), int32(bv1.Index())}, - Coeffs: []int64{1, 1}, - Domain: []int64{-5, -4, -2, -1, 6, 15}, - }, - }, + Constraint: &cmpb.ConstraintProto_Linear{&cmpb.LinearConstraintProto{ + Vars: []int32{int32(iv1.Index()), int32(bv1.Index())}, + Coeffs: []int64{1, 1}, + Domain: []int64{-5, -4, -2, -1, 6, 15}, + }}, }, }, { @@ -1008,13 +983,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()), int32(bv1.Index())}, - Coeffs: []int64{1, 1}, - Domain: []int64{2, 6}, - }, - }, + Constraint: &cmpb.ConstraintProto_Linear{&cmpb.LinearConstraintProto{ + Vars: []int32{int32(iv1.Index()), int32(bv1.Index())}, + Coeffs: []int64{1, 1}, + Domain: []int64{2, 6}, + }}, }, }, { @@ -1025,13 +998,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{10, 10}, - }, - }, + Constraint: &cmpb.ConstraintProto_Linear{&cmpb.LinearConstraintProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{1}, + Domain: []int64{10, 10}, + }}, }, }, { @@ -1042,13 +1013,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, 10}, - }, - }, + Constraint: &cmpb.ConstraintProto_Linear{&cmpb.LinearConstraintProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{1}, + Domain: []int64{math.MinInt64, 10}, + }}, }, }, { @@ -1059,13 +1028,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}, - }, - }, + Constraint: &cmpb.ConstraintProto_Linear{&cmpb.LinearConstraintProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{1}, + Domain: []int64{math.MinInt64, 9}, + }}, }, }, { @@ -1076,13 +1043,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{10, math.MaxInt64}, - }, - }, + Constraint: &cmpb.ConstraintProto_Linear{&cmpb.LinearConstraintProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{1}, + Domain: []int64{10, math.MaxInt64}, + }}, }, }, { @@ -1093,13 +1058,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{11, math.MaxInt64}, - }, - }, + Constraint: &cmpb.ConstraintProto_Linear{&cmpb.LinearConstraintProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{1}, + Domain: []int64{11, math.MaxInt64}, + }}, }, }, { @@ -1110,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}, + }}, }, }, { @@ -1127,30 +1088,28 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, 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, - }, + 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, }, }, - }, + }}, }, }, { @@ -1161,13 +1120,11 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, 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())}, - }, - }, + Constraint: &cmpb.ConstraintProto_Element{&cmpb.ElementConstraintProto{ + Index: int32(iv1.Index()), + Target: int32(iv4.Index()), + Vars: []int32{int32(iv2.Index()), int32(iv3.Index())}, + }}, }, }, { @@ -1178,16 +1135,14 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, 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()), - }, + 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()), }, - }, + }}, }, }, { @@ -1198,12 +1153,10 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, 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())}, - }, - }, + Constraint: &cmpb.ConstraintProto_Inverse{&cmpb.InverseConstraintProto{ + FDirect: []int32{int32(iv1.Index()), int32(iv2.Index())}, + FInverse: []int32{int32(iv3.Index()), int32(iv4.Index())}, + }}, }, }, { @@ -1214,24 +1167,22 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_LinMax{ - &cmpb.LinearArgumentProto{ - Target: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, + Constraint: &cmpb.ConstraintProto_LinMax{&cmpb.LinearArgumentProto{ + 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}, }, }, - }, + }}, }, }, { @@ -1242,24 +1193,22 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_LinMax{ - &cmpb.LinearArgumentProto{ - Target: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, + Constraint: &cmpb.ConstraintProto_LinMax{&cmpb.LinearArgumentProto{ + 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}, }, }, - }, + }}, }, }, { @@ -1270,24 +1219,22 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_IntProd{ - &cmpb.LinearArgumentProto{ - Target: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, + Constraint: &cmpb.ConstraintProto_IntProd{&cmpb.LinearArgumentProto{ + 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}, }, }, - }, + }}, }, }, { @@ -1298,24 +1245,22 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_IntDiv{ - &cmpb.LinearArgumentProto{ - Target: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, + Constraint: &cmpb.ConstraintProto_IntDiv{&cmpb.LinearArgumentProto{ + 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}, }, }, - }, + }}, }, }, { @@ -1326,24 +1271,22 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_LinMax{ - &cmpb.LinearArgumentProto{ - Target: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, + Constraint: &cmpb.ConstraintProto_LinMax{&cmpb.LinearArgumentProto{ + 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}, }, }, - }, + }}, }, }, { @@ -1354,24 +1297,22 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_IntMod{ - &cmpb.LinearArgumentProto{ - Target: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, + Constraint: &cmpb.ConstraintProto_IntMod{&cmpb.LinearArgumentProto{ + 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}, }, }, - }, + }}, }, }, { @@ -1382,11 +1323,9 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_NoOverlap{ - &cmpb.NoOverlapConstraintProto{ - Intervals: []int32{int32(interval1.Index()), int32(interval2.Index())}, - }, - }, + Constraint: &cmpb.ConstraintProto_NoOverlap{&cmpb.NoOverlapConstraintProto{ + Intervals: []int32{int32(interval1.Index()), int32(interval2.Index())}, + }}, }, }, { @@ -1399,12 +1338,10 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_NoOverlap_2D{ - &cmpb.NoOverlap2DConstraintProto{ - XIntervals: []int32{int32(interval1.Index()), int32(interval3.Index())}, - YIntervals: []int32{int32(interval2.Index()), int32(interval4.Index())}, - }, - }, + Constraint: &cmpb.ConstraintProto_NoOverlap_2D{&cmpb.NoOverlap2DConstraintProto{ + XIntervals: []int32{int32(interval1.Index()), int32(interval3.Index())}, + YIntervals: []int32{int32(interval2.Index()), int32(interval4.Index())}, + }}, }, }, { @@ -1416,13 +1353,11 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_Circuit{ - &cmpb.CircuitConstraintProto{ - Tails: []int32{0}, - Heads: []int32{1}, - Literals: []int32{int32(bv1.Index())}, - }, - }, + Constraint: &cmpb.ConstraintProto_Circuit{&cmpb.CircuitConstraintProto{ + Tails: []int32{0}, + Heads: []int32{1}, + Literals: []int32{int32(bv1.Index())}, + }}, }, }, { @@ -1434,13 +1369,11 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_Routes{ - &cmpb.RoutesConstraintProto{ - Tails: []int32{0}, - Heads: []int32{1}, - Literals: []int32{int32(bv1.Index())}, - }, - }, + Constraint: &cmpb.ConstraintProto_Routes{&cmpb.RoutesConstraintProto{ + Tails: []int32{0}, + Heads: []int32{1}, + Literals: []int32{int32(bv1.Index())}, + }}, }, }, { @@ -1453,12 +1386,10 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_Table{ - &cmpb.TableConstraintProto{ - Vars: []int32{int32(iv1.Index()), int32(iv2.Index())}, - Values: []int64{0, 2, 1, 3}, - }, - }, + Constraint: &cmpb.ConstraintProto_Table{&cmpb.TableConstraintProto{ + Vars: []int32{int32(iv1.Index()), int32(iv2.Index())}, + Values: []int64{0, 2, 1, 3}, + }}, }, }, { @@ -1470,24 +1401,22 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_Reservoir{ - &cmpb.ReservoirConstraintProto{ - MinLevel: 10, - MaxLevel: 20, - TimeExprs: []*cmpb.LinearExpressionProto{ - &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, - Coeffs: []int64{2}, - }, + Constraint: &cmpb.ConstraintProto_Reservoir{&cmpb.ReservoirConstraintProto{ + MinLevel: 10, + MaxLevel: 20, + TimeExprs: []*cmpb.LinearExpressionProto{ + &cmpb.LinearExpressionProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{2}, }, - LevelChanges: []*cmpb.LinearExpressionProto{ - &cmpb.LinearExpressionProto{ - Offset: 15, - }, + }, + LevelChanges: []*cmpb.LinearExpressionProto{ + &cmpb.LinearExpressionProto{ + Offset: 15, }, - ActiveLiterals: []int32{int32(one.Index())}, }, - }, + ActiveLiterals: []int32{int32(one.Index())}, + }}, }, }, { @@ -1500,16 +1429,14 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_Automaton{ - &cmpb.AutomatonConstraintProto{ - Vars: []int32{int32(iv1.Index()), int32(iv2.Index())}, - StartingState: 0, - FinalStates: []int64{5, 10}, - TransitionTail: []int64{0, 2}, - TransitionHead: []int64{1, 3}, - TransitionLabel: []int64{10, 15}, - }, - }, + Constraint: &cmpb.ConstraintProto_Automaton{&cmpb.AutomatonConstraintProto{ + Vars: []int32{int32(iv1.Index()), int32(iv2.Index())}, + StartingState: 0, + FinalStates: []int64{5, 10}, + TransitionTail: []int64{0, 2}, + TransitionHead: []int64{1, 3}, + TransitionLabel: []int64{10, 15}, + }}, }, }, { @@ -1521,21 +1448,19 @@ func TestCpModelBuilder_Constraints(t *testing.T) { return m.GetConstraints()[c.Index()] }, want: &cmpb.ConstraintProto{ - Constraint: &cmpb.ConstraintProto_Cumulative{ - &cmpb.CumulativeConstraintProto{ - Capacity: &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv1.Index())}, + Constraint: &cmpb.ConstraintProto_Cumulative{&cmpb.CumulativeConstraintProto{ + Capacity: &cmpb.LinearExpressionProto{ + Vars: []int32{int32(iv1.Index())}, + Coeffs: []int64{1}, + }, + Intervals: []int32{int32(interval1.Index())}, + Demands: []*cmpb.LinearExpressionProto{ + &cmpb.LinearExpressionProto{ + Vars: []int32{int32(iv2.Index())}, Coeffs: []int64{1}, }, - Intervals: []int32{int32(interval1.Index())}, - Demands: []*cmpb.LinearExpressionProto{ - &cmpb.LinearExpressionProto{ - Vars: []int32{int32(iv2.Index())}, - Coeffs: []int64{1}, - }, - }, }, - }, + }}, }, }, } diff --git a/ortools/sat/go/cpmodel/cp_solver.go b/ortools/sat/go/cpmodel/cp_solver.go index 752b5d05624..e50a1f2f5b6 100644 --- a/ortools/sat/go/cpmodel/cp_solver.go +++ b/ortools/sat/go/cpmodel/cp_solver.go @@ -18,10 +18,10 @@ import ( "sync" "unsafe" + "google.golang.org/protobuf/proto" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" - - "google.golang.org/protobuf/proto" ) /* diff --git a/ortools/sat/go/cpmodel/cp_solver_c.cc b/ortools/sat/go/cpmodel/cp_solver_c.cc index 1f5b36808f4..e8bba37b13e 100644 --- a/ortools/sat/go/cpmodel/cp_solver_c.cc +++ b/ortools/sat/go/cpmodel/cp_solver_c.cc @@ -14,13 +14,12 @@ #include "ortools/sat/go/cpmodel/cp_solver_c.h" #include -#include -#include "absl/status/status.h" -#include "absl/strings/internal/memutil.h" -#include "ortools/base/logging.h" +#include "absl/log/check.h" +#include "ortools/base/memutil.h" #include "ortools/sat/cp_model.pb.h" #include "ortools/sat/cp_model_solver.h" +#include "ortools/sat/model.h" #include "ortools/sat/sat_parameters.pb.h" #include "ortools/util/time_limit.h" @@ -28,13 +27,6 @@ namespace operations_research::sat { namespace { -char* memdup(const char* s, size_t slen) { - void* copy; - if ((copy = malloc(slen)) == nullptr) return nullptr; - memcpy(copy, s, slen); - return reinterpret_cast(copy); -} - CpSolverResponse solveWithParameters(std::atomic* const limit_reached, const CpModelProto& proto, const SatParameters& params) { @@ -81,7 +73,7 @@ void SolveCpInterruptible(void* const limit_reached, const void* creq, CHECK(res.SerializeToString(&res_str)); *cres_len = static_cast(res_str.size()); - *cres = memdup(res_str.data(), *cres_len); + *cres = strings::memdup(res_str.data(), *cres_len); CHECK(*cres != nullptr); } diff --git a/ortools/sat/samples/assumptions_sample_sat.go b/ortools/sat/samples/assumptions_sample_sat.go index 56f700c5d99..c46d994a916 100644 --- a/ortools/sat/samples/assumptions_sample_sat.go +++ b/ortools/sat/samples/assumptions_sample_sat.go @@ -17,8 +17,8 @@ package main import ( "fmt" - "github.com/golang/glog" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" "ortools/sat/go/cpmodel" ) @@ -62,6 +62,6 @@ func assumptionsSampleSat() error { func main() { if err := assumptionsSampleSat(); err != nil { - glog.Exitf("assumptionsSampleSat returned with error: %v", err) + log.Exitf("assumptionsSampleSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/binpacking_problem_sat.go b/ortools/sat/samples/binpacking_problem_sat.go index 5ba42154794..96c1251cd43 100644 --- a/ortools/sat/samples/binpacking_problem_sat.go +++ b/ortools/sat/samples/binpacking_problem_sat.go @@ -18,7 +18,7 @@ package main import ( "fmt" - "github.com/golang/glog" + log "github.com/golang/glog" "ortools/sat/go/cpmodel" ) @@ -30,7 +30,7 @@ const ( ) type item struct { - Cost, Copies int64_t + Cost, Copies int64 } func binpackingProblemSat() error { @@ -116,6 +116,6 @@ func binpackingProblemSat() error { func main() { if err := binpackingProblemSat(); err != nil { - glog.Exitf("binpackingProblemSat returned with error: %v", err) + log.Exitf("binpackingProblemSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/boolean_product_sample_sat.go b/ortools/sat/samples/boolean_product_sample_sat.go index 874294ebd8c..8d724195c7a 100644 --- a/ortools/sat/samples/boolean_product_sample_sat.go +++ b/ortools/sat/samples/boolean_product_sample_sat.go @@ -17,10 +17,10 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" + log "github.com/golang/glog" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) func booleanProductSample() error { @@ -68,6 +68,6 @@ func booleanProductSample() error { func main() { err := booleanProductSample() if err != nil { - glog.Exitf("booleanProductSample returned with error: %v", err) + log.Exitf("booleanProductSample returned with error: %v", err) } } diff --git a/ortools/sat/samples/channeling_sample_sat.go b/ortools/sat/samples/channeling_sample_sat.go index 88db3279f9f..dab99823e60 100644 --- a/ortools/sat/samples/channeling_sample_sat.go +++ b/ortools/sat/samples/channeling_sample_sat.go @@ -17,11 +17,11 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) func channelingSampleSat() error { @@ -76,6 +76,6 @@ func channelingSampleSat() error { func main() { if err := channelingSampleSat(); err != nil { - glog.Exitf("channelingSampleSat returned with error: %v", err) + log.Exitf("channelingSampleSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/earliness_tardiness_cost_sample_sat.go b/ortools/sat/samples/earliness_tardiness_cost_sample_sat.go index 43f7c2f1812..ce4135506cd 100644 --- a/ortools/sat/samples/earliness_tardiness_cost_sample_sat.go +++ b/ortools/sat/samples/earliness_tardiness_cost_sample_sat.go @@ -18,11 +18,11 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) const ( @@ -85,6 +85,6 @@ func earlinessTardinessCostSampleSat() error { func main() { if err := earlinessTardinessCostSampleSat(); err != nil { - glog.Exitf("earlinessTardinessCostSampleSat returned with error: %v", err) + log.Exitf("earlinessTardinessCostSampleSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/interval_sample_sat.go b/ortools/sat/samples/interval_sample_sat.go index e0e2776631b..5a3a2545918 100644 --- a/ortools/sat/samples/interval_sample_sat.go +++ b/ortools/sat/samples/interval_sample_sat.go @@ -17,7 +17,7 @@ package main import ( "fmt" - "github.com/golang/glog" + log "github.com/golang/glog" "ortools/sat/go/cpmodel" ) @@ -53,6 +53,6 @@ func intervalSampleSat() error { func main() { if err := intervalSampleSat(); err != nil { - glog.Exitf("intervalSampleSat returned with error: %v", err) + log.Exitf("intervalSampleSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/literal_sample_sat.go b/ortools/sat/samples/literal_sample_sat.go index be171a9161c..7cfec06ccbc 100644 --- a/ortools/sat/samples/literal_sample_sat.go +++ b/ortools/sat/samples/literal_sample_sat.go @@ -15,7 +15,7 @@ package main import ( - "github.com/golang/glog" + log "github.com/golang/glog" "ortools/sat/go/cpmodel" ) @@ -25,7 +25,7 @@ func literalSampleSat() { x := model.NewBoolVar().WithName("x") notX := x.Not() - glog.Infof("x = %d, x.Not() = %d", x.Index(), notX.Index()) + log.Infof("x = %d, x.Not() = %d", x.Index(), notX.Index()) } func main() { diff --git a/ortools/sat/samples/no_overlap_sample_sat.go b/ortools/sat/samples/no_overlap_sample_sat.go index ce5fccab1ee..e69fc2a0cc6 100644 --- a/ortools/sat/samples/no_overlap_sample_sat.go +++ b/ortools/sat/samples/no_overlap_sample_sat.go @@ -17,8 +17,8 @@ package main import ( "fmt" - "github.com/golang/glog" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" "ortools/sat/go/cpmodel" ) @@ -85,6 +85,6 @@ func noOverlapSampleSat() error { func main() { if err := noOverlapSampleSat(); err != nil { - glog.Exitf("noOverlapSampleSat returned with error: %v", err) + log.Exitf("noOverlapSampleSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/nqueens_sat.go b/ortools/sat/samples/nqueens_sat.go index b2a7b8323c0..198237f6bd1 100644 --- a/ortools/sat/samples/nqueens_sat.go +++ b/ortools/sat/samples/nqueens_sat.go @@ -17,7 +17,7 @@ package main import ( "fmt" - "github.com/golang/glog" + log "github.com/golang/glog" "ortools/sat/go/cpmodel" ) @@ -30,7 +30,7 @@ func nQueensSat() error { // of the board. The value of each variable is the row that the queen is in. var queenRows []cpmodel.LinearArgument for i := 0; i < boardSize; i++ { - queenRows = append(queenRows, model.NewIntVar(0, int64_t(boardSize-1))) + queenRows = append(queenRows, model.NewIntVar(0, int64(boardSize-1))) } // The following sets the constraint that all queens are in different rows. @@ -40,8 +40,8 @@ func nQueensSat() error { var diag1 []cpmodel.LinearArgument var diag2 []cpmodel.LinearArgument for i := 0; i < boardSize; i++ { - diag1 = append(diag1, cpmodel.NewConstant(int64_t(i)).Add(queenRows[i])) - diag2 = append(diag2, cpmodel.NewConstant(int64_t(-i)).Add(queenRows[i])) + diag1 = append(diag1, cpmodel.NewConstant(int64(i)).Add(queenRows[i])) + diag2 = append(diag2, cpmodel.NewConstant(int64(-i)).Add(queenRows[i])) } model.AddAllDifferent(diag1...) model.AddAllDifferent(diag2...) @@ -59,7 +59,7 @@ func nQueensSat() error { fmt.Printf("Objective: %v\n", response.GetObjectiveValue()) fmt.Printf("Solution:\n") - for i := int64_t(0); i < boardSize; i++ { + for i := int64(0); i < boardSize; i++ { for j := 0; j < boardSize; j++ { if cpmodel.SolutionIntegerValue(response, queenRows[j]) == i { fmt.Print("Q") @@ -76,6 +76,6 @@ func nQueensSat() error { func main() { err := nQueensSat() if err != nil { - glog.Exitf("nQueensSat returned with error: %v", err) + log.Exitf("nQueensSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/nurses_sat.go b/ortools/sat/samples/nurses_sat.go index 59ffa83e8a7..c8fbb492841 100644 --- a/ortools/sat/samples/nurses_sat.go +++ b/ortools/sat/samples/nurses_sat.go @@ -17,7 +17,7 @@ package main import ( "fmt" - "github.com/golang/glog" + log "github.com/golang/glog" "ortools/sat/go/cpmodel" ) @@ -121,6 +121,6 @@ func nursesSat() error { func main() { if err := nursesSat(); err != nil { - glog.Exitf("nursesSat returned with error: %v", err) + log.Exitf("nursesSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/optional_interval_sample_sat.go b/ortools/sat/samples/optional_interval_sample_sat.go index b586dce62dd..2f50f8a411c 100644 --- a/ortools/sat/samples/optional_interval_sample_sat.go +++ b/ortools/sat/samples/optional_interval_sample_sat.go @@ -18,7 +18,7 @@ package main import ( "fmt" - "github.com/golang/glog" + log "github.com/golang/glog" "ortools/sat/go/cpmodel" ) @@ -51,6 +51,6 @@ func optionalIntervalSampleSat() error { func main() { if err := optionalIntervalSampleSat(); err != nil { - glog.Exitf("optionalIntervalSampleSat returned with error: %v", err) + log.Exitf("optionalIntervalSampleSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/rabbits_and_pheasants_sat.go b/ortools/sat/samples/rabbits_and_pheasants_sat.go index f00a76adb65..c828874a168 100644 --- a/ortools/sat/samples/rabbits_and_pheasants_sat.go +++ b/ortools/sat/samples/rabbits_and_pheasants_sat.go @@ -18,8 +18,8 @@ package main import ( "fmt" - "github.com/golang/glog" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" "ortools/sat/go/cpmodel" ) @@ -58,6 +58,6 @@ func rabbitsAndPheasants() error { func main() { if err := rabbitsAndPheasants(); err != nil { - glog.Exitf("rabbitsAndPheasants returned with error: %v", err) + log.Exitf("rabbitsAndPheasants returned with error: %v", err) } } diff --git a/ortools/sat/samples/ranking_sample_sat.go b/ortools/sat/samples/ranking_sample_sat.go index cb1a3989840..d81c01e1fd1 100644 --- a/ortools/sat/samples/ranking_sample_sat.go +++ b/ortools/sat/samples/ranking_sample_sat.go @@ -17,8 +17,8 @@ package main import ( "fmt" - "github.com/golang/glog" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" "ortools/sat/go/cpmodel" ) @@ -89,7 +89,7 @@ func rankingSampleSat() error { for t := 0; t < numTasks; t++ { start := model.NewIntVarFromDomain(horizon) - duration := cpmodel.NewConstant(int64_t(t + 1)) + duration := cpmodel.NewConstant(int64(t + 1)) end := model.NewIntVarFromDomain(horizon) var presence cpmodel.BoolVar if t < numTasks/2 { @@ -160,6 +160,6 @@ func rankingSampleSat() error { func main() { if err := rankingSampleSat(); err != nil { - glog.Exitf("rankingSampleSat returned with error: %v", err) + log.Exitf("rankingSampleSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/search_for_all_solutions_sample_sat.go b/ortools/sat/samples/search_for_all_solutions_sample_sat.go index 17c4e3f84d4..2324f031de4 100644 --- a/ortools/sat/samples/search_for_all_solutions_sample_sat.go +++ b/ortools/sat/samples/search_for_all_solutions_sample_sat.go @@ -18,10 +18,10 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" + log "github.com/golang/glog" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) func searchForAllSolutionsSampleSat() error { @@ -63,6 +63,6 @@ func searchForAllSolutionsSampleSat() error { func main() { if err := searchForAllSolutionsSampleSat(); err != nil { - glog.Exitf("searchForAllSolutionsSampleSat returned with error: %v", err) + log.Exitf("searchForAllSolutionsSampleSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/simple_sat_program.go b/ortools/sat/samples/simple_sat_program.go index 0430d34fb49..cf48a942849 100644 --- a/ortools/sat/samples/simple_sat_program.go +++ b/ortools/sat/samples/simple_sat_program.go @@ -17,8 +17,8 @@ package main import ( "fmt" - "github.com/golang/glog" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" "ortools/sat/go/cpmodel" ) @@ -55,6 +55,6 @@ func simpleSatProgram() error { func main() { if err := simpleSatProgram(); err != nil { - glog.Exitf("simpleSatProgram returned with error: %v", err) + log.Exitf("simpleSatProgram returned with error: %v", err) } } diff --git a/ortools/sat/samples/solution_hinting_sample_sat.go b/ortools/sat/samples/solution_hinting_sample_sat.go index 59b2766c2be..70f15710c91 100644 --- a/ortools/sat/samples/solution_hinting_sample_sat.go +++ b/ortools/sat/samples/solution_hinting_sample_sat.go @@ -17,8 +17,8 @@ package main import ( "fmt" - "github.com/golang/glog" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" "ortools/sat/go/cpmodel" ) @@ -60,6 +60,6 @@ func solutionHintingSampleSat() error { func main() { if err := solutionHintingSampleSat(); err != nil { - glog.Exitf("solutionHintingSampleSat returned with error: %v", err) + log.Exitf("solutionHintingSampleSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/solve_and_print_intermediate_solutions_sample_sat.go b/ortools/sat/samples/solve_and_print_intermediate_solutions_sample_sat.go index f1a0d86507d..7885073bac4 100644 --- a/ortools/sat/samples/solve_and_print_intermediate_solutions_sample_sat.go +++ b/ortools/sat/samples/solve_and_print_intermediate_solutions_sample_sat.go @@ -17,10 +17,10 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" + log "github.com/golang/glog" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) func solveAndPrintIntermediateSolutionsSampleSat() error { @@ -65,6 +65,6 @@ func solveAndPrintIntermediateSolutionsSampleSat() error { func main() { if err := solveAndPrintIntermediateSolutionsSampleSat(); err != nil { - glog.Exitf("solveAndPrintIntermediateSolutionsSampleSat returned with error: %v", err) + log.Exitf("solveAndPrintIntermediateSolutionsSampleSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/solve_with_time_limit_sample_sat.go b/ortools/sat/samples/solve_with_time_limit_sample_sat.go index 4fe04c95a8d..b7f968b336b 100644 --- a/ortools/sat/samples/solve_with_time_limit_sample_sat.go +++ b/ortools/sat/samples/solve_with_time_limit_sample_sat.go @@ -17,11 +17,11 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) func solveWithTimeLimitSampleSat() error { @@ -63,6 +63,6 @@ func solveWithTimeLimitSampleSat() error { func main() { if err := solveWithTimeLimitSampleSat(); err != nil { - glog.Exitf("solveWithTimeLimitSampleSat returned with error: %v", err) + log.Exitf("solveWithTimeLimitSampleSat returned with error: %v", err) } } diff --git a/ortools/sat/samples/step_function_sample_sat.go b/ortools/sat/samples/step_function_sample_sat.go index 5fb4e66f9f3..b04a04d9acf 100644 --- a/ortools/sat/samples/step_function_sample_sat.go +++ b/ortools/sat/samples/step_function_sample_sat.go @@ -17,11 +17,11 @@ package main import ( "fmt" - "github.com/golang/glog" - "golang/protobuf/v2/proto/proto" - cmpb "ortools/sat/cp_model_go_proto" + log "github.com/golang/glog" + cmpb "github.com/google/or-tools/ortools/sat/proto/cpmodel" + sppb "github.com/google/or-tools/ortools/sat/proto/satparameters" + "google.golang.org/protobuf/proto" "ortools/sat/go/cpmodel" - sppb "ortools/sat/sat_parameters_go_proto" ) func stepFunctionSampleSat() error { @@ -94,6 +94,6 @@ func stepFunctionSampleSat() error { func main() { if err := stepFunctionSampleSat(); err != nil { - glog.Exitf("stepFunctionSampleSat returned with error: %v", err) + log.Exitf("stepFunctionSampleSat returned with error: %v", err) } } diff --git a/ortools/sat/sat_parameters.proto b/ortools/sat/sat_parameters.proto index 2cc412d4aa9..870cf2cf8bf 100644 --- a/ortools/sat/sat_parameters.proto +++ b/ortools/sat/sat_parameters.proto @@ -15,15 +15,15 @@ syntax = "proto2"; package operations_research.sat; +option csharp_namespace = "Google.OrTools.Sat"; +option go_package = "github.com/google/or-tools/ortools/sat/proto/satparameters"; option java_package = "com.google.ortools.sat"; option java_multiple_files = true; -option csharp_namespace = "Google.OrTools.Sat"; - // Contains the definitions for all the sat algorithm parameters and their // default values. // -// NEXT TAG: 299 +// NEXT TAG: 300 message SatParameters { // In some context, like in a portfolio of search, it makes sense to name a // given parameters set for logging purpose.