Skip to content

Commit

Permalink
Added link to better examples. Added more covers.
Browse files Browse the repository at this point in the history
  • Loading branch information
d-krupke committed May 9, 2024
1 parent 963e7b6 commit ba36b0e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 44 deletions.
30 changes: 8 additions & 22 deletions 02_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,28 +167,14 @@ make it easier to identify and correct errors in the modeling process.

### More examples

Here are some further examples, if you are not yet satisfied:

- [N-queens](https://developers.google.com/optimization/cp/queens) (this one
also gives you a quick introduction to constraint programming, but it may be
misleading because CP-SAT is no classical
[FD(Finite Domain)-solver](http://www.gameaipro.com/GameAIPro2/GameAIPro2_Chapter26_Rolling_Your_Own_Finite-Domain_Constraint_Solver.pdf).
This example probably has been modified from the previous generation, which is
also explained at the end.)
- [Employee Scheduling](https://developers.google.com/optimization/scheduling/employee_scheduling)
- [Job Shop Problem](https://developers.google.com/optimization/scheduling/job_shop)
- More examples can be found in
[the official repository](https://github.com/google/or-tools/tree/stable/ortools/sat/samples)
for multiple languages (yes, CP-SAT does support more than just Python). As
the Python-examples are named in
[snake-case](https://en.wikipedia.org/wiki/Snake_case), they are at the end of
the list.

Ok. Now that you have seen a minimal model, let us look on what options we have
to model a problem. Note that an experienced optimizer may be able to model most
problems with just the elements shown above, but showing your intentions may
help CP-SAT optimize your problem better. Contrary to Mixed Integer Programming,
you also do not need to fine-tune any
If you are not yet satisfied,
[this folder contains many Jupyter Notebooks with examples from the developers](https://github.com/google/or-tools/tree/stable/examples/notebook/sat).

Ok. Now that you have seen a minimal model, let us next look on what options we
have to model a problem. Note that an experienced optimizer may be able to model
most problems with just the elements shown above, but showing your intentions
may help CP-SAT optimize your problem better. Contrary to Mixed Integer
Programming, you also do not need to fine-tune any
[Big-Ms](https://en.wikipedia.org/wiki/Big_M_method) (a reason to model
higher-level constraints, such as conditional constraints that are only enforced
if some variable is set to true, in MIPs yourself, because the computer is not
Expand Down
2 changes: 2 additions & 0 deletions 03_big_picture.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## Alternatives: CP-SAT's Place in the World of Optimization

![Cover Image World of Optimization](https://raw.githubusercontent.com/d-krupke/cpsat-primer/main/images/logo_8.webp)

When you begin exploring optimization, you will encounter a plethora of tools,
techniques, and communities. It can be overwhelming, as these groups, while
sharing many similarities, also differ significantly. They might use the same
Expand Down
2 changes: 2 additions & 0 deletions 07_under_the_hood.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## How does it work?

![Cover Image How](https://raw.githubusercontent.com/d-krupke/cpsat-primer/main/images/logo_7.webp)

CP-SAT is a versatile _portfolio_ solver, centered around a _Lazy Clause
Generation (LCG)_ based Constraint Programming Solver, although it encompasses a
broader spectrum of technologies.
Expand Down
9 changes: 9 additions & 0 deletions 08_benchmarking.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ provides the results for the `AddCircuit`-model.
| lin318 | 318 | 92.43 | 41915 | 52025 | 19% |
| pr439 | 439 | 94.22 | 105610 | 163452 | 35% |

A last option is to split the y-axis into the part where the solving time is
still within the time limit, and the part where it is not and the optimality gap
becomes relevant. Such a plot has some benefits but can also be difficult to
scale or aggregate.

| ![Split Plot](./images/split_plot.png) |
| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| This plot splits the y-axis into a part where the instances can still be solved within the time limit, such that the time can be shown, and the part where the time limit is exceeded, such that the optimality gap can be shown. This example was generated by my student assistant Rouven Kniep, and he is working on creating an easy-to-use script for such plots. |

This should highlight that often you need a combination of different benchmarks
and plots to get a good understanding of the performance of your model.

Expand Down
43 changes: 21 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,28 +374,14 @@ make it easier to identify and correct errors in the modeling process.

### More examples

Here are some further examples, if you are not yet satisfied:

- [N-queens](https://developers.google.com/optimization/cp/queens) (this one
also gives you a quick introduction to constraint programming, but it may be
misleading because CP-SAT is no classical
[FD(Finite Domain)-solver](http://www.gameaipro.com/GameAIPro2/GameAIPro2_Chapter26_Rolling_Your_Own_Finite-Domain_Constraint_Solver.pdf).
This example probably has been modified from the previous generation, which is
also explained at the end.)
- [Employee Scheduling](https://developers.google.com/optimization/scheduling/employee_scheduling)
- [Job Shop Problem](https://developers.google.com/optimization/scheduling/job_shop)
- More examples can be found in
[the official repository](https://github.com/google/or-tools/tree/stable/ortools/sat/samples)
for multiple languages (yes, CP-SAT does support more than just Python). As
the Python-examples are named in
[snake-case](https://en.wikipedia.org/wiki/Snake_case), they are at the end of
the list.

Ok. Now that you have seen a minimal model, let us look on what options we have
to model a problem. Note that an experienced optimizer may be able to model most
problems with just the elements shown above, but showing your intentions may
help CP-SAT optimize your problem better. Contrary to Mixed Integer Programming,
you also do not need to fine-tune any
If you are not yet satisfied,
[this folder contains many Jupyter Notebooks with examples from the developers](https://github.com/google/or-tools/tree/stable/examples/notebook/sat).

Ok. Now that you have seen a minimal model, let us next look on what options we
have to model a problem. Note that an experienced optimizer may be able to model
most problems with just the elements shown above, but showing your intentions
may help CP-SAT optimize your problem better. Contrary to Mixed Integer
Programming, you also do not need to fine-tune any
[Big-Ms](https://en.wikipedia.org/wiki/Big_M_method) (a reason to model
higher-level constraints, such as conditional constraints that are only enforced
if some variable is set to true, in MIPs yourself, because the computer is not
Expand All @@ -412,6 +398,8 @@ very good at that).

## Alternatives: CP-SAT's Place in the World of Optimization

![Cover Image World of Optimization](https://raw.githubusercontent.com/d-krupke/cpsat-primer/main/images/logo_8.webp)

When you begin exploring optimization, you will encounter a plethora of tools,
techniques, and communities. It can be overwhelming, as these groups, while
sharing many similarities, also differ significantly. They might use the same
Expand Down Expand Up @@ -3275,6 +3263,8 @@ class KnapsackSolver:

## How does it work?

![Cover Image How](https://raw.githubusercontent.com/d-krupke/cpsat-primer/main/images/logo_7.webp)

CP-SAT is a versatile _portfolio_ solver, centered around a _Lazy Clause
Generation (LCG)_ based Constraint Programming Solver, although it encompasses a
broader spectrum of technologies.
Expand Down Expand Up @@ -3850,6 +3840,15 @@ provides the results for the `AddCircuit`-model.
| lin318 | 318 | 92.43 | 41915 | 52025 | 19% |
| pr439 | 439 | 94.22 | 105610 | 163452 | 35% |

A last option is to split the y-axis into the part where the solving time is
still within the time limit, and the part where it is not and the optimality gap
becomes relevant. Such a plot has some benefits but can also be difficult to
scale or aggregate.

| ![Split Plot](./images/split_plot.png) |
| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| This plot splits the y-axis into a part where the instances can still be solved within the time limit, such that the time can be shown, and the part where the time limit is exceeded, such that the optimality gap can be shown. This example was generated by my student assistant Rouven Kniep, and he is working on creating an easy-to-use script for such plots. |

This should highlight that often you need a combination of different benchmarks
and plots to get a good understanding of the performance of your model.

Expand Down
Binary file added images/logo_7.webp
Binary file not shown.
Binary file added images/logo_8.webp
Binary file not shown.
Binary file added images/split_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ba36b0e

Please sign in to comment.