Skip to content

Commit

Permalink
Fix #1097: simplify the process + udpate docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cprudhom committed Jul 3, 2024
1 parent 962f55b commit fbd1f99
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 234 deletions.
21 changes: 0 additions & 21 deletions parsers/DIMACS.md

This file was deleted.

88 changes: 0 additions & 88 deletions parsers/MINIZINC.md

This file was deleted.

29 changes: 0 additions & 29 deletions parsers/MPS.md

This file was deleted.

31 changes: 2 additions & 29 deletions parsers/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,7 @@
choco-parsers
=============

`choco-parsers` is an extension library for [choco-solver](https://github.com/chocoteam/choco-solver).

It aims at importing models to various format.
`choco-parsers` is an extension that aims at dealing with models to various format.
It provides a parser for the FlatZinc language, a low-level solver input language that is the target language for [MiniZinc](http://www.minizinc.org/),
a parser for [XCSP3](http://xcsp.org), an intermediate integrated XML-based format,
a parser for [DIMACS CNF](http://www.satcompetition.org/2009/format-benchmarks2009.html), the SAT solver competitions input file format
and a parser for [MPS](http://miplib.zib.de/) a file format for presenting and archiving linear programming (LP) and mixed integer programming problems.

* [Download](https://github.com/chocoteam/choco-parsers/releases/latest) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.choco-solver/choco-parsers/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.choco-solver/choco-parsers)
* [Parsing a file](#par)
* [MiniZinc](./MINIZINC.md)
* [XCSP3](XCSP3.md)
* [DIMACS CNF](DIMACS.md)
* [MPS](MPS.md)


<a name="par"></a>
### Parsing a file

By default, the extension of a file helps choosing the accurate parser.
Thus, any supported file (FlatZinc, XCSP3, DIMACS CNF or MPS) can be parsed and solved using the following command:

```java -jar .:/path/to/choco-parsers-4.0.5-with-dependencies.jar [options] <file>```

Only the file name is mandatory.
Alternatively, if the file has no explicit extension, the option ```-pa``` followed a digit between 1 and 4
can be declared to specify the parser to use; 1: FlatZinc, 2: XCSP3, 3: DIMACS and 4: MPS.

A Bash file named ```parse.sh``` can also be found in `./src/main/bash/` that handles basic options.

Finally, if one can to use a specific parser directly, in that case, click on the right link above.
and a parser for [DIMACS CNF](http://www.satcompetition.org/2009/format-benchmarks2009.html), the SAT solver competitions input file format.
35 changes: 0 additions & 35 deletions parsers/XCSP3.md

This file was deleted.

2 changes: 1 addition & 1 deletion parsers/src/main/minizinc/choco.msc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Choco FlatZinc executable",
"version" : "4.10.15",
"mznlib" : "/Users/kyzrsoze/Sources/CHOCO/continuous-branch/parsers/src/main/minizinc/mzn_lib/",
"executable" : "/Users/kyzrsoze/Sources/CHOCO/continuous-branch/parsers/src/main/minizinc/fzn-choco",
"executable" : "/Users/kyzrsoze/Sources/CHOCO/continuous-branch/parsers/src/main/minizinc/fzn-choco.sh",
"tags": ["cp","int"],
"stdFlags": ["-a","-f","-n","-p","-r","-s","-t","--cp-profiler"],
"supportsMzn": false,
Expand Down
30 changes: 10 additions & 20 deletions parsers/src/main/minizinc/docker/Dockerfile.dms
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,28 @@
# Using the MiniZinc Challenge docker image
FROM minizinc/mznc2024:latest as build

# Install Java 17 @
# Install Java 21 @
RUN apt-get update && \
apt-get install -y \
vim python3.11 python3-pip patchelf && \
pip install nuitka
#default-jre-headless
openjdk-21-jre-headless \
python3 \
vim

# The following command is used to disable caching for the ADD command and the next ones
ADD "https://www.random.org/cgi-bin/randbyte?nbytes=10&format=h" skipcache
# Copy Choco's files from the local repository
COPY ./parsers/target/choco-parsers-*-light.jar /choco/choco.jar
COPY ./parsers/src/main/minizinc/fzn-choco.py /choco/fzn-choco.py
COPY ./parsers/src/main/minizinc/fzn-choco.sh /choco/fzn-choco.sh
COPY ./parsers/src/main/minizinc/choco.msc /choco/choco.msc
COPY ./parsers/src/main/minizinc/mzn_lib/* /choco/mzn-lib/

# Update files
RUN sed -i 's&JAR_FILE=.*&JAR_FILE="/choco/choco.jar"&g' /choco/fzn-choco.py && \
#sed -i 's&python3 .*&python3 /choco/fzn-choco.py "$@"&g' /choco/fzn-choco.sh && \
sed -i 's&"mznlib".*&"mznlib":"/choco/mzn-lib/",&g' /choco/choco.msc && \
sed -i 's&"executable".*&"executable":"/choco/fzn-choco.bin",&g' /choco/choco.msc && \
cd /choco/ && \
# Now compile the python file to a binary file called fzn-choco.bin \
python3 -m nuitka /choco/fzn-choco.py && \
cd /minizinc/

# 2. Stage: Move the Choco executable and its MiniZinc library to the MiniZinc Challenge docker image
FROM minizinc/mznc2024:latest as main

RUN apt-get update && \
apt-get install -y \
#default-jre-headless
openjdk-21-jre-headless vim

COPY --from=build /choco/ /choco/

RUN echo '{"mzn_solver_path": ["/choco/"],' > $HOME/.minizinc/Preferences.json && \
sed -i 's&"executable".*&"executable":"/choco/fzn-choco.sh",&g' /choco/choco.msc && \
cd /minizinc/ && \
echo '{"mzn_solver_path": ["/choco/"],' > $HOME/.minizinc/Preferences.json && \
echo '"tagDefaults": [["", "org.choco.choco"]]}' >> $HOME/.minizinc/Preferences.json
4 changes: 2 additions & 2 deletions parsers/src/main/minizinc/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ docker build -f ./Dockerfile.dms -t chocoteam/choco-solver-mzn:<tag> <path-to-ch
```

where
- `<tag>` is the tag of the Docker image (e.g. `latest` or `4.10.0`)
- `<tag>` is the tag of the Docker image (e.g. `4.10.0`)
- `<path-to-choco-solver>` is the path to the local repository of choco-solver (relative or absolute).

Then you can run the Docker image with the following command:

```bash
docker run --rm <repository>:<tag> minizinc fd.mpc /minizinc/test.mzn /minizinc/2.dzn
docker run --rm chocoteam/choco-solver-mzn:<tag> minizinc fd.mpc /minizinc/test.mzn /minizinc/2.dzn
```

4 changes: 4 additions & 0 deletions parsers/src/main/minizinc/fzn-choco.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
:: Call the python script with the arguments passed to this script
set "PY=%~dp0fzn-choco.py"
python3 %PY% %*
10 changes: 2 additions & 8 deletions parsers/src/main/minizinc/fzn-choco.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
import os
import sys

from timeit import default_timer as timer

start = timer()

# THIS IS WHERE YOU NEED TO CHANGE THE PATH TO THE JAR FILE
JAR_FILE= '/Users/kyzrsoze/Sources/CHOCO/continuous-branch/parsers/target/choco-parsers-4.10.15-SNAPSHOT-light.jar'

Expand Down Expand Up @@ -106,10 +102,8 @@ def parse_id_port(value):
if args.cp_profiler:
arguments += ' --cp-profiler ' + str(args.cp_profiler[0]) + ',' + str(args.cp_profiler[1])

cmd = f'java {args.jvm_args} -cp .:{args.jar_file} org.chocosolver.parser.flatzinc.ChocoFZN {args.fzn_file} {arguments}'
cmd = f'java {args.jvm_args} -cp {args.jar_file} org.chocosolver.parser.flatzinc.ChocoFZN {args.fzn_file} {arguments}'

# if __lvl__ == 'INFO':
print(f'Running command: {cmd}')
end = timer()
print("% ", end - start, "sec")
#cprint(f'Running command: {cmd}')
os.system(cmd)
4 changes: 4 additions & 0 deletions parsers/src/main/minizinc/fzn-choco.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Call the python script with the arguments passed to this script
python3 "$(dirname "$0")/fzn-choco.py" "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ EXAMPLES:
Additionnal arguments:
$> xcsp3_choco.sh --jargs \"-Xmx128m\" -tl 100 ./choco.jar ./alpha.xml
$> ./xcsp3-exec -a -tl 100 -p 2 ./alpha.xml
"

Expand Down

0 comments on commit fbd1f99

Please sign in to comment.