From eb0f319cd6a2110a8e460ff881d3e5fca7b9c28a Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Fri, 22 Oct 2021 00:50:21 +0200 Subject: [PATCH] Sync github with google --- .../java/constraint_solver.i | 6 ++--- .../constraint_solver/samples/CpIsFunCp.java | 2 -- .../constraint_solver/samples/cp_is_fun_cp.cc | 2 +- .../constraint_solver/samples/cp_is_fun_cp.py | 27 +++++++++---------- .../samples/SolveWithTimeLimitSampleSat.java | 3 +-- .../samples/StopAfterNSolutionsSampleSat.java | 3 +-- 6 files changed, 18 insertions(+), 25 deletions(-) diff --git a/ortools/constraint_solver/java/constraint_solver.i b/ortools/constraint_solver/java/constraint_solver.i index 4b9e329d7d..eb645a6099 100644 --- a/ortools/constraint_solver/java/constraint_solver.i +++ b/ortools/constraint_solver/java/constraint_solver.i @@ -856,13 +856,13 @@ import java.util.HashSet; public void keepAliveDecisionBuilder(DecisionBuilder db) {} %} -%typemap(javain, +%typemap(javain, post=" keepAliveDecisionBuilder($javainput);" ) DecisionBuilder* "DecisionBuilder.getCPtr($javainput)" -%typemap(javain, +%typemap(javain, post=" keepAliveDecisionBuilder($javainput);" - ) const std::vector& dbs "$javainput" + ) const std::vector& dbs "$javainput" %ignore Solver::SearchLogParameters; %ignore Solver::ActiveSearch; diff --git a/ortools/constraint_solver/samples/CpIsFunCp.java b/ortools/constraint_solver/samples/CpIsFunCp.java index d1f593ec10..ce99892edf 100644 --- a/ortools/constraint_solver/samples/CpIsFunCp.java +++ b/ortools/constraint_solver/samples/CpIsFunCp.java @@ -23,9 +23,7 @@ package com.google.ortools.constraintsolver.samples; import com.google.ortools.Loader; import com.google.ortools.constraintsolver.DecisionBuilder; import com.google.ortools.constraintsolver.IntVar; -import com.google.ortools.constraintsolver.IntExpr; import com.google.ortools.constraintsolver.Solver; -import com.google.ortools.constraintsolver.main; // [END import] /** Cryptarithmetic puzzle. */ diff --git a/ortools/constraint_solver/samples/cp_is_fun_cp.cc b/ortools/constraint_solver/samples/cp_is_fun_cp.cc index 63fc337802..e089a0eefb 100644 --- a/ortools/constraint_solver/samples/cp_is_fun_cp.cc +++ b/ortools/constraint_solver/samples/cp_is_fun_cp.cc @@ -1,4 +1,4 @@ -// Copyright 2011-2021 Google LLC +// Copyright 2010-2021 Google LLC // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/ortools/constraint_solver/samples/cp_is_fun_cp.py b/ortools/constraint_solver/samples/cp_is_fun_cp.py index 00b89c8393..6066255a21 100755 --- a/ortools/constraint_solver/samples/cp_is_fun_cp.py +++ b/ortools/constraint_solver/samples/cp_is_fun_cp.py @@ -12,8 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # [START program] -""" -Cryptarithmetic puzzle +"""Cryptarithmetic puzzle. First attempt to solve equation CP + IS + FUN = TRUE where each letter represents a unique digit. @@ -22,7 +21,6 @@ This problem has 72 different solutions in base 10. """ # [START import] from ortools.constraint_solver import pywrapcp -from os import abort # [END import] @@ -33,11 +31,11 @@ def main(): # [END solver] # [START variables] - kBase = 10 + base = 10 # Decision variables. - digits = list(range(0, kBase)) - digits_without_zero = list(range(1, kBase)) + digits = list(range(0, base)) + digits_without_zero = list(range(1, base)) c = solver.IntVar(digits_without_zero, 'C') p = solver.IntVar(digits, 'P') i = solver.IntVar(digits_without_zero, 'I') @@ -53,7 +51,7 @@ def main(): letters = [c, p, i, s, f, u, n, t, r, e] # Verify that we have enough digits. - assert kBase >= len(letters) + assert base >= len(letters) # [END variables] # Define constraints. @@ -61,22 +59,21 @@ def main(): solver.Add(solver.AllDifferent(letters)) # CP + IS + FUN = TRUE - solver.Add(p + s + n + kBase * (c + i + u) + kBase * kBase * f == e + - kBase * u + kBase * kBase * r + kBase * kBase * kBase * t) + solver.Add(p + s + n + base * (c + i + u) + base * base * f == e + + base * u + base * base * r + base * base * base * t) # [END constraints] # [START solve] solution_count = 0 - db = solver.Phase(letters, solver.INT_VAR_DEFAULT, - solver.INT_VALUE_DEFAULT) + db = solver.Phase(letters, solver.INT_VAR_DEFAULT, solver.INT_VALUE_DEFAULT) solver.NewSearch(db) while solver.NextSolution(): print(letters) # Is CP + IS + FUN = TRUE? - assert (kBase * c.Value() + p.Value() + kBase * i.Value() + s.Value() + - kBase * kBase * f.Value() + kBase * u.Value() + - n.Value() == kBase * kBase * kBase * t.Value() + - kBase * kBase * r.Value() + kBase * u.Value() + e.Value()) + assert (base * c.Value() + p.Value() + base * i.Value() + s.Value() + + base * base * f.Value() + base * u.Value() + + n.Value() == base * base * base * t.Value() + + base * base * r.Value() + base * u.Value() + e.Value()) solution_count += 1 solver.EndSearch() print(f'Number of solutions found: {solution_count}') diff --git a/ortools/sat/samples/SolveWithTimeLimitSampleSat.java b/ortools/sat/samples/SolveWithTimeLimitSampleSat.java index ed4d5759c0..e14f81c003 100644 --- a/ortools/sat/samples/SolveWithTimeLimitSampleSat.java +++ b/ortools/sat/samples/SolveWithTimeLimitSampleSat.java @@ -22,7 +22,7 @@ import com.google.ortools.sat.IntVar; /** Solves a problem with a time limit. */ public final class SolveWithTimeLimitSampleSat { - public static void main(String[] args) throws Exception { + public static void main(String[] args) { Loader.loadNativeLibraries(); // Create the model. CpModel model = new CpModel(); @@ -46,7 +46,6 @@ public final class SolveWithTimeLimitSampleSat { System.out.println("z = " + solver.value(z)); } } - private SolveWithTimeLimitSampleSat() {} } // [END program] diff --git a/ortools/sat/samples/StopAfterNSolutionsSampleSat.java b/ortools/sat/samples/StopAfterNSolutionsSampleSat.java index 657b81df4f..01c02fbd15 100644 --- a/ortools/sat/samples/StopAfterNSolutionsSampleSat.java +++ b/ortools/sat/samples/StopAfterNSolutionsSampleSat.java @@ -50,7 +50,7 @@ public final class StopAfterNSolutionsSampleSat { private final int solutionLimit; } - public static void main(String[] args) throws Exception { + public static void main(String[] args) { Loader.loadNativeLibraries(); // Create the model. CpModel model = new CpModel(); @@ -75,7 +75,6 @@ public final class StopAfterNSolutionsSampleSat { throw new RuntimeException("Did not stop the search correctly."); } } - private StopAfterNSolutionsSampleSat() {} } // [END program]