Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] fzn-choco.exe doesn't work #1097

Closed
SYury opened this issue May 20, 2024 · 6 comments
Closed

[BUG] fzn-choco.exe doesn't work #1097

SYury opened this issue May 20, 2024 · 6 comments
Assignees
Labels
Milestone

Comments

@SYury
Copy link

SYury commented May 20, 2024

Describe the bug
I tried adding Choco to MiniZinc IDE on Windows and encountered several problems with fzn-choco.exe script:

  1. While the documentation suggests adding it to config file as-is, in practice it doesn't work because despite the .exe extension it's actually a bat script, so the execution fails.
  2. The multi-line usage description is not parsed correctly as a multi-line variable.
  3. There is some problem with if-else syntax in argument parsing, the script dies with The syntax of the command is incorrect.. And even if it's fixed, there also is a logical error in the parsing, it considers path to flatzinc file as unrecognized argument.
  4. There are various small problems with setting variables and executing java, too many to describe every problem separately.

I'm not sure if the script is just wrong or some problems are caused by my Windows installation,

To Reproduce
Try adding Choco to MiniZinc on Windows.

Expected behavior
Everything should work.

Possible solution
I managed to make it work with trial and error. It's quite ugly and I'm not sure I found every possible bug, but I can make a pull request if you want.

Environment (please complete the following information):

  • Choco-solver version: 4.10.14 with the fzn-choco.exe from current master branch
  • MiniZinc IDE 2.8.4
  • Windows 10
@SYury SYury added the bug label May 20, 2024
@cprudhom
Copy link
Member

I have no doubt that the script can be improved in many ways.
The fact is I have no computer with Windows running on it, so I tried to adapt it from the shell file I use (fzn-choco.sh file) using Copilot and a plugin from IntelliJ 😄.
I could possibly look around for a PC and really test the script.

@cprudhom cprudhom self-assigned this Jun 10, 2024
@cprudhom
Copy link
Member

Hello
I started to study an alternative in Python.
The main problem was due to MiniZincIDE that only support executable MiniZinc doc.

But Nuitka makes possible to turn a Python app into an executable.
It seems quite straightforward.

I suggest using the Python script instead of the bash script. This lets you run choco-solver with MiniZinc options outside MiniZincIDE. You can also integrate the executable you create with Nuitka directly into MiniZincIDE.

@cprudhom
Copy link
Member

I pushed some changes.
You can have a look (master branch) at MINIZINC.md that explains hopefully clearly enough how to generate the executable for MiniZinc.
Would you accept to test the solution?

@SYury
Copy link
Author

SYury commented Jun 27, 2024

Thank you, I'll test it when I have time.

@SYury
Copy link
Author

SYury commented Jul 2, 2024

I tested the script and I have two comments:

  1. In line 109 the class path is passed as -cp .:{args.jar_file} and I had to remove .: to make it work on Windows
  2. Using nuitka turned out to be quite inconvenient because it downloads a C compiler to build the executable. Fortunately, it's possible to wrap the python script in a simple .bat:
set "PY=%~dp0fzn-choco.py"
python3 %PY% %*

and passing this bat script to minizinc works. Maybe it should be added somewhere in the docs.

@cprudhom
Copy link
Member

cprudhom commented Jul 2, 2024

It seems a simpler alternative to maintain.
I will simply remove the nuitka steps and add 2 files:

fzn-choco.sh

#!/bin/bash

# Call the python script with the arguments passed to this script
python3 fzn-choco.py "$@"

fzn-choco.bat

@echo off
:: Call the python script with the arguments passed to this script
set "PY=%~dp0fzn-choco.py"
python3 %PY% %*

and update the documentation and remove the .: from fzn-choco.py.

@cprudhom cprudhom reopened this Jul 2, 2024
@cprudhom cprudhom added this to the 4.11.0 milestone Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants