add javadoc to java sat samples

polish samples, integrate in md files
This commit is contained in:
Laurent Perron
2018-11-15 14:32:20 -08:00
parent e86822f804
commit 3dc6d1ee2c
24 changed files with 57 additions and 29 deletions

View File

@@ -71,6 +71,7 @@ import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.IntVar;
import com.google.ortools.sat.Literal;
/** Code sample to demonstrate Boolean variable and literals. */
public class LiteralSampleSat {
static { System.loadLibrary("jniortools"); }
@@ -170,6 +171,7 @@ import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.IntVar;
import com.google.ortools.sat.Literal;
/** Code sample to demonstrates a simple Boolean constraint. */
public class BoolOrSampleSat {
static { System.loadLibrary("jniortools"); }

View File

@@ -168,6 +168,7 @@ import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverSolutionCallback;
import com.google.ortools.sat.IntVar;
/** Link integer constraints together. */
public class ChannelingSampleSat {
static { System.loadLibrary("jniortools"); }
@@ -469,6 +470,7 @@ import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.IntVar;
/** Solves a bin packing problem with the CP-SAT solver. */
public class BinPackingProblemSat {
static { System.loadLibrary("jniortools"); }

View File

@@ -35,13 +35,13 @@ from __future__ import print_function
from ortools.sat.python import cp_model
def SimpleSatProblem():
def SimpleSatProgram():
model = cp_model.CpModel()
x = model.NewBoolVar('x')
print(x)
SimpleSatProblem()
SimpleSatProgram()
```
## C++ code samples
@@ -56,7 +56,7 @@ This class is just a helper to fill in the cp_model protobuf.
namespace operations_research {
namespace sat {
void SimpleSatProblem() {
void SimpleSatProgram() {
CpModelBuilder cp_model;
const IntVar x = cp_model.NewBoolVar().WithName("x");
@@ -66,7 +66,7 @@ void SimpleSatProblem() {
} // namespace operations_research
int main() {
operations_research::sat::SimpleSatProblem();
operations_research::sat::SimpleSatProgram();
return EXIT_SUCCESS;
}
@@ -81,7 +81,8 @@ The Java code implements the same interface as the Python code, with a
import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.IntVar;
public class SimpleSatProblem {
/** Creates a single Boolean variable. */
public class SimpleSatProgram {
static { System.loadLibrary("jniortools"); }
@@ -105,7 +106,7 @@ The C\# code implements the same interface as the Python code, with a
using System;
using Google.OrTools.Sat;
public class SimpleSatProblem
public class SimpleSatProgram
{
static void Main()
{

View File

@@ -90,6 +90,7 @@ import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.IntVar;
import com.google.ortools.sat.IntervalVar;
/** Code sample to demonstrates how to build an interval. */
public class IntervalSampleSat {
static { System.loadLibrary("jniortools"); }
@@ -149,6 +150,7 @@ from ortools.sat.python import cp_model
def OptionalIntervalSampleSat():
"""Build an optional interval."""
model = cp_model.CpModel()
horizon = 100
@@ -214,6 +216,7 @@ import com.google.ortools.sat.IntVar;
import com.google.ortools.sat.IntervalVar;
import com.google.ortools.sat.Literal;
/** Code sample to demonstrates how to build an optional interval. */
public class OptionalIntervalSampleSat {
static { System.loadLibrary("jniortools"); }
@@ -870,14 +873,18 @@ import com.google.ortools.sat.Literal;
import java.util.ArrayList;
import java.util.List;
// This code takes a list of interval variables in a noOverlap constraint, and a parallel list of
// integer variables and enforces the following constraint:
// - rank[i] == -1 iff interval[i] is not active.
// - rank[i] == number of active intervals that precede interval[i].
/** Code sample to demonstrates how to rank intervals. */
public class RankingSampleSat {
static { System.loadLibrary("jniortools"); }
/**
* This code takes a list of interval variables in a noOverlap constraint, and a parallel list of
* integer variables and enforces the following constraint
*
* - rank[i] == -1 iff interval[i] is not active.
* - rank[i] == number of active intervals that precede interval[i].
*/
static void rankTasks(CpModel model, IntVar[] starts, Literal[] presences, IntVar[] ranks) {
int numTasks = starts.length;

View File

@@ -101,7 +101,7 @@ import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.IntVar;
/** Solve a simple problem with three variables and one different constraint. */
/** Minimal CP-SAT example to showcase calling the solver. */
public class SimpleSolveSampleSat {
static { System.loadLibrary("jniortools"); }
@@ -140,7 +140,7 @@ model.
using System;
using Google.OrTools.Sat;
public class SimpleSolveSat
public class SimpleSolveSampleSat
{
static void Main()
{
@@ -272,6 +272,7 @@ import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.IntVar;
/** Solves a problem with a time limit. */
public class SolveWithTimeLimitSampleSat {
static { System.loadLibrary("jniortools"); }
@@ -461,6 +462,7 @@ import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverSolutionCallback;
import com.google.ortools.sat.IntVar;
/** Solves an optimization problem and displays all intermediate solutions. */
public class SolveAndPrintIntermediateSolutionsSampleSat {
static { System.loadLibrary("jniortools"); }
@@ -701,6 +703,7 @@ import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverSolutionCallback;
import com.google.ortools.sat.IntVar;
/** Code sample that solves a model and displays all solutions. */
public class SearchForAllSolutionsSampleSat {
static { System.loadLibrary("jniortools"); }
@@ -954,6 +957,7 @@ import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverSolutionCallback;
import com.google.ortools.sat.IntVar;
/** Code sample that solves a model and displays a small number of solutions. */
public class StopAfterNSolutionsSampleSat {
static { System.loadLibrary("jniortools"); }

View File

@@ -16,6 +16,7 @@ import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverStatus;
import com.google.ortools.sat.IntVar;
/** Solves a bin packing problem with the CP-SAT solver. */
public class BinPackingProblemSat {
static {
System.loadLibrary("jniortools");

View File

@@ -15,6 +15,7 @@ import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.IntVar;
import com.google.ortools.sat.Literal;
/** Code sample to demonstrates a simple Boolean constraint. */
public class BoolOrSampleSat {
static {
System.loadLibrary("jniortools");

View File

@@ -18,6 +18,7 @@ import com.google.ortools.sat.DecisionStrategyProto;
import com.google.ortools.sat.IntVar;
import com.google.ortools.sat.SatParameters;
/** Link integer constraints together. */
public class ChannelingSampleSat {
static {
System.loadLibrary("jniortools");

View File

@@ -17,6 +17,7 @@ import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverSolutionCallback;
import com.google.ortools.sat.IntVar;
/** Cryptarithmetic puzzle. */
public class CpIsFunSat {
static {
System.loadLibrary("jniortools");

View File

@@ -15,6 +15,7 @@ import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.IntVar;
import com.google.ortools.sat.IntervalVar;
/** Code sample to demonstrates how to build an interval. */
public class IntervalSampleSat {
static {
System.loadLibrary("jniortools");

View File

@@ -15,6 +15,7 @@ import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.IntVar;
import com.google.ortools.sat.Literal;
/** Code sample to demonstrate Boolean variable and literals. */
public class LiteralSampleSat {
static {
System.loadLibrary("jniortools");

View File

@@ -16,6 +16,7 @@ import com.google.ortools.sat.IntVar;
import com.google.ortools.sat.IntervalVar;
import com.google.ortools.sat.Literal;
/** Code sample to demonstrates how to build an optional interval. */
public class OptionalIntervalSampleSat {
static {
System.loadLibrary("jniortools");

View File

@@ -20,15 +20,19 @@ import com.google.ortools.sat.Literal;
import java.util.ArrayList;
import java.util.List;
// This code takes a list of interval variables in a noOverlap constraint, and a parallel list of
// integer variables and enforces the following constraint:
// - rank[i] == -1 iff interval[i] is not active.
// - rank[i] == number of active intervals that precede interval[i].
/** Code sample to demonstrates how to rank intervals. */
public class RankingSampleSat {
static {
System.loadLibrary("jniortools");
}
/**
* This code takes a list of interval variables in a noOverlap constraint, and a parallel list of
* integer variables and enforces the following constraint
*
* - rank[i] == -1 iff interval[i] is not active.
* - rank[i] == number of active intervals that precede interval[i].
*/
static void rankTasks(CpModel model, IntVar[] starts, Literal[] presences, IntVar[] ranks) {
int numTasks = starts.length;

View File

@@ -16,6 +16,7 @@ import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverSolutionCallback;
import com.google.ortools.sat.IntVar;
/** Code sample that solves a model and displays all solutions. */
public class SearchForAllSolutionsSampleSat {
static {
System.loadLibrary("jniortools");

View File

@@ -14,18 +14,13 @@
using System;
using Google.OrTools.Sat;
public class CodeSamplesSat
public class SimpleSatProgram
{
static void CodeSample()
static void Main()
{
// Creates the model.
CpModel model = new CpModel();
// Creates the Boolean variable.
IntVar x = model.NewBoolVar("x");
}
static void Main()
{
CodeSample();
}
}

View File

@@ -14,6 +14,7 @@
import com.google.ortools.sat.CpModel;
import com.google.ortools.sat.IntVar;
/** Creates a single Boolean variable. */
public class SimpleSatProgram {
static {
System.loadLibrary("jniortools");

View File

@@ -14,7 +14,7 @@
using System;
using Google.OrTools.Sat;
public class SimpleSolveSat
public class SimpleSolveSampleSat
{
static void Main()
{

View File

@@ -16,7 +16,7 @@ import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverStatus;
import com.google.ortools.sat.IntVar;
/** Solve a simple problem with three variables and one different constraint. */
/** Minimal CP-SAT example to showcase calling the solver. */
public class SimpleSolveSampleSat {
static {
System.loadLibrary("jniortools");

View File

@@ -16,6 +16,7 @@ import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverSolutionCallback;
import com.google.ortools.sat.IntVar;
/** Solves an optimization problem and displays all intermediate solutions. */
public class SolveAndPrintIntermediateSolutionsSampleSat {
static {
System.loadLibrary("jniortools");

View File

@@ -16,6 +16,7 @@ import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverStatus;
import com.google.ortools.sat.IntVar;
/** Solves a problem with a time limit. */
public class SolveWithTimeLimitSampleSat {
static {
System.loadLibrary("jniortools");

View File

@@ -16,6 +16,7 @@ import com.google.ortools.sat.CpSolver;
import com.google.ortools.sat.CpSolverSolutionCallback;
import com.google.ortools.sat.IntVar;
/** Code sample that solves a model and displays a small number of solutions. */
public class StopAfterNSolutionsSampleSat {
static {
System.loadLibrary("jniortools");

View File

@@ -20,6 +20,7 @@ from ortools.sat.python import cp_model
def OptionalIntervalSampleSat():
"""Build an optional interval."""
model = cp_model.CpModel()
horizon = 100

View File

@@ -16,7 +16,7 @@
namespace operations_research {
namespace sat {
void CodeSample() {
void SimpleSatProgram() {
CpModelBuilder cp_model;
const IntVar x = cp_model.NewBoolVar().WithName("x");
@@ -26,7 +26,7 @@ void CodeSample() {
} // namespace operations_research
int main() {
operations_research::sat::CodeSample();
operations_research::sat::SimpleSatProgram();
return EXIT_SUCCESS;
}

View File

@@ -19,10 +19,10 @@ from __future__ import print_function
from ortools.sat.python import cp_model
def CodeSample():
def SimpleSatProgram():
model = cp_model.CpModel()
x = model.NewBoolVar('x')
print(x)
CodeSample()
SimpleSatProgram()