Skip to content

Commit

Permalink
Integer domains (#620)
Browse files Browse the repository at this point in the history
* changed to L_int.md and implemented suggestions

* add integer domain notebooks

* add integer domains notebook and update file

* Update letting_domain.md to fix L_int.md link

---------

Co-authored-by: Özgür Akgün <ozgurakgun@gmail.com>
  • Loading branch information
N-J-Martin and ozgurakgun committed Nov 18, 2023
1 parent 4df549b commit 7611e79
Show file tree
Hide file tree
Showing 4 changed files with 322 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/bits/keyword/letting_domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ letting x be domain int(1..10)
Types of domains:

- [boolean](https://github.com/conjure-cp/conjure/blob/main/docs/bits/type/L_bool.md)
- [integer](...)
- [integer](https://github.com/conjure-cp/conjure/blob/main/docs/bits/type/L_int.md)
- [enumerated](https://github.com/conjure-cp/conjure/blob/main/docs/bits/keyword/new_type_enum.md)
- [unnamed](...)
- [tuple](...)
Expand Down
22 changes: 22 additions & 0 deletions docs/bits/type/L_int.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# int

Integer domains can be defined by
```
int (<ranges list>)
```

If no range is provided, then represents infinite domain of integers.

An integer range is either a single integer
```
int(n)
```

or a list of sequential integers with a given lower and upper bound (inclusive).
```
int(a..b, c..d, ...)
```

Values must be between -2<sup>62</sup> + 1 and 2<sup>62</sup> - 1.

See this demonstrated [here](https://github.com/conjure-cp/conjure/blob/main/docs/notebooks/IntegerDomains.ipynb).
2 changes: 1 addition & 1 deletion docs/bits/type/matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ The domain used to index the elements may be specifed too, such that.
They are not ordered, but can be compared using equality operators.
Two matrices are only equal if their indices are the same.

Read more about matrix domains [here](https://conjure.readthedocs.io/en/latest/essence.html#types).
Read more about matrix domains [here](https://conjure.readthedocs.io/en/latest/essence.html#types) and see them demonstrated [here](https://github.com/conjure-cp/conjure/blob/main/docs/notebooks/matrix.ipynb).
298 changes: 298 additions & 0 deletions docs/notebooks/IntegerDomains.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/conjure-cp/conjure/blob/main/docs/notebooks/IntegerDomains.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "-s7Zcn-_U6cb"
},
"source": [
"## Integer Domains"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "MRiI4lvEVE0I",
"outputId": "e1aa764c-b6b6-42cc-cd31-6e3f159d6b5b"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Installing Conjure version v2.5.1 and Conjure Notebook version v0.0.10...\n",
"Conjure is already installed.\n",
"Conjure notebook is already installed.\n",
"Conjure: The Automated Constraint Modelling Tool\n",
"Release version 2.5.1\n",
"Repository version a9cbc2e (2023-11-07 23:44:00 +0000)\n",
"The conjure extension is already loaded. To reload it, use:\n",
" %reload_ext conjure\n"
]
}
],
"source": [
"!source <(curl -s https://raw.githubusercontent.com/conjure-cp/conjure-notebook/v0.0.10/scripts/install-colab.sh)\n",
"%load_ext conjure"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "LPY0op8yXAMk"
},
"source": [
"You can define integer domains in different ways."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4vRxGMLYXjcO"
},
"source": [
"For example, you can define integer domains as seen [here](https://github.com/conjure-cp/conjure/blob/main/docs/notebooks/letting_domain.ipynb)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "tPPGY5hOXuBm"
},
"source": [
"Using a single integer:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 317
},
"id": "mjv1Gl-IU_84",
"outputId": "7384d866-348e-42a3-ddb2-80619222a566"
},
"outputs": [
{
"data": {
"text/markdown": [
"```json\n",
"{\"x\": 3}\n",
"```"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"| Statistic | Value |\n",
"|:-|-:|\n",
"| SolverTotalTime | 0.005 |\n",
"| SavileRowClauseOut | 0 |\n",
"| SavileRowTotalTime | 0.067 |\n",
"| SolverFailures | 1 |\n",
"| SolverSatisfiable | 1 |\n",
"| SavileRowTimeOut | 0 |\n",
"| SolverTimeOut | 0 |\n",
"| SolverNodes | 1 |\n"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%conjure --number-of-solutions=all\n",
"find x: int(3)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "R2LATZaEX3KY"
},
"source": [
"By defining a lower and upper bound (inclusive)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 365
},
"id": "v2DmTqRSYDAg",
"outputId": "4d640acc-8ca3-4fd7-b7f0-5868301d9b47"
},
"outputs": [
{
"data": {
"text/markdown": [
"## Solution 1"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"```json\n",
"[{\"x\": 1}, {\"x\": 2}, {\"x\": 3}]\n",
"```"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"| Statistic | Value |\n",
"|:-|-:|\n",
"| SolverTotalTime | 0.002 |\n",
"| SavileRowClauseOut | 0 |\n",
"| SavileRowTotalTime | 0.076 |\n",
"| SolverFailures | 3 |\n",
"| SolverSatisfiable | 1 |\n",
"| SavileRowTimeOut | 0 |\n",
"| SolverTimeOut | 0 |\n",
"| SolverNodes | 3 |\n"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%conjure --number-of-solutions=all\n",
"find x: int(1..3)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3jOSvw7FYP6E"
},
"source": [
"Or, a list of integer ranges."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 365
},
"id": "oalwCZA8WSyJ",
"outputId": "471e84a5-1245-421e-ec69-3a987f93656c"
},
"outputs": [
{
"data": {
"text/markdown": [
"## Solution 1"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"```json\n",
"[{\"x\": 1}, {\"x\": 2}, {\"x\": 3}, {\"x\": 4}, {\"x\": 8}, {\"x\": 9}, {\"x\": 10}]\n",
"```"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"| Statistic | Value |\n",
"|:-|-:|\n",
"| SolverTotalTime | 0.005 |\n",
"| SavileRowClauseOut | 0 |\n",
"| SavileRowTotalTime | 0.062 |\n",
"| SolverFailures | 7 |\n",
"| SolverSatisfiable | 1 |\n",
"| SavileRowTimeOut | 0 |\n",
"| SolverTimeOut | 0 |\n",
"| SolverNodes | 7 |\n"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%conjure --number-of-solutions=all\n",
"find x: int(1..3, 4, 8..10)"
]
}
],
"metadata": {
"colab": {
"authorship_tag": "ABX9TyM6pbXXsB13v7hrNL5+/vY+",
"include_colab_link": true,
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit 7611e79

Please sign in to comment.