Giter VIP home page Giter VIP logo

choco-parsers's Introduction

choco-parsers

choco-parsers is an extension library for choco-solver.

It aims at importing 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, a parser for XCSP3, an intermediate integrated XML-based format and a parser for MPS a file format for presenting and archiving linear programming (LP) and mixed integer programming problems.

It also provides utilities to export a model written with Choco to a JSON format and to import a JSON format file into a Model.

Parsing a file

By default, the extension of a file helps choosing the accurate parser. Thus, any supported file (FlatZinc, XCSP3, MPS or JSON) 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: MPS and 4: JSON.

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.

choco-parsers's People

Contributors

cprudhom avatar jgfages avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

choco-parsers's Issues

unexpected behavior in some mps tests

Good day!

I've been testing the pulp integration done in issue #15 and while running pulp's internal tests we have arrived to a couple of bizarre results. For each result I'm sending the mps file of the test and the sol file I got. They're all very small examples.

Here I explain each of the cases:

  • pulpTest009: choco returns optimal instead of infeasible
  • pulpTest011: choco gives a non-optimal result while saying it's optimal.

Two of the cases are actually unbounded problems. Not sure how or if choco detects this and how it communicates it:

  • pulpTest012: choco says optimal and returns a solution instead of unbounded.
  • pulpTest123: choco crashes in a memory leak instead of saying it's unbounded.

thanks!

Franco
pulp_tests.zip

Connecting choco with PuLP

Good day!

I'm interested on integrating choco with python's PuLP library to test it with the models that I've modeled so far.
This library (PuLP) lets the user build one single model and then communicates with several linear programming solvers: CBC, GUROBI, CPLEX, XPRESS, glpk.

I guess there are multiple ways of doing the integration. One very simple way pulp communicates with some of these solvers is the following:

  1. it creates a .mps or .lp file
  2. it then calls the solver as a command line with the file as input,
  3. the solver generates the output as a .sol file
  4. PulP reads the output and converts it into the corresponding python variables.

I'm wondering if this could be done with choco. That is:

  1. Is it possible to use choco as a command line application?
  2. Is it possible for choco to read .mps or .lp files?

I'm aware that much of the functionality of the CP solver is lost sometimes doing these kinds of translations, specially if the models come from the LP / MIP world. Still I think it's useful to be able to at least test the solver for lazy people like me.

Of course, I'd be more than glad to edit the necessary parts in PuLP if needed (although I'm not the maintainer of the repo).

thanks!

Franco

Error in Knapsack cstr

  1. the initial sort with ratio was bugged
  2. the parser should rely on the choco-solver implementation

write solution (and possibly logging) into file

It would be interesting to have the option to write the solution into a file instead of only showing it in the screen. This could be configured by a new command line option like the following:

-o <file_path>

Also, although less important, would be to have the log output (progress) written into, yet another, file.

That way, we could at the same time show the output in screen and write it into a file and not mix the solution logging with the solution itself.

Thanks!

Franco

Ease parser access

In order to simplify the usage of the parser, there should be some entry points, kind of monitors, to provide an access to users to interact with parsed files.

java 1.8 needed and wrong package for FZNLayout

In order to compile the project, I needed to change the version of the Java flavor in pom.xml from 1.7 to 1.8:

1.8 1.8

Indeed, in the file src/main/java/parser/flatzinc/Flatzinc.java, there is the following construction that requires Java 1.8:
ParserListener::afterParsingFile

I needed to change also in the file src/main/antlr4/parser/flatzinc/Flatzinc4Parser.g4:
import parser.flatzinc.FZNLayout;
into
import parser.flatzinc.layout.FZNLayout;

Define free search

The refactoring of the parsers removed default free search declaration.
It needs to be done for int and set vars.

Infinite solving time while using "-a -bb 3" options

Using the following program to solve a very easy instance of n-queens problem leads to an infinite solving time. This problem only occurs when we request to print all the solution (-a) found using an ActivityBased strategy (-bb 3).

public class demo {
  public static void main(String[] argv) throws Exception {
    org.chocosolver.parser.xcsp.XCSP xcsp = new org.chocosolver.parser.xcsp.XCSP();
    xcsp.addListener(new org.chocosolver.parser.xcsp.BaseXCSPListener(xcsp));
    xcsp.setUp(new String[]{"queens.xcsp3", "-a", "-bb", "3"});
    xcsp.defineSettings(new org.chocosolver.parser.xcsp.XCSPSettings());
    xcsp.createSolver();
    xcsp.buildModel();
    xcsp.configureSearch();
    xcsp.solve();
  }
}

queens.xcsp3:

<instance format="XCSP3" type="CSP">
<variables>
<array id="q" size="[4]"> 0..3 </array>
</variables>
<constraints>
<allDifferent>
q[]
</allDifferent>
<allDifferent>
add(q[0],0) add(q[1],1) add(q[2],2) add(q[3],3)
</allDifferent>
<allDifferent>
sub(q[0],0) sub(q[1],1) sub(q[2],2) sub(q[3],3)
</allDifferent>
</constraints>
</instance>

Export a choco model to XCSP3

Hi choco team,

I want to know if there is a way to export my choco 4.5 model to XCSP3 format.

thank you in advance .

XCSP: Build problem?

I am trying to export a Choco Model to JSON using Choco parsers. (Choco 4.0.6, Choco-parsers 4.0.4)

However, a dependency (xcsp3) in the pom.xml of choco-parsers cannot be resolved:

	<dependency>
		<groupId>org.choco-solver</groupId>
		<artifactId>choco-parsers</artifactId>
		<version>4.0.4</version>
	</dependency>

Description Resource Path Location Type
Missing artifact xcsp3:xcsp3:jar:1.0.1-SNAPSHOT pom.xml /SpringCaas line 3 Maven Dependency Problem

I checked the XCSP website, and did not find a direct match. Is there an easy workaround? Or where to find the xcsp3:xcsp3:jar:1.0.1-SNAPSHOT ?

Thank you!

Reading XCSP3 files

  • basic implementation of XCSP3 parser
  • scripts
  • implementing core constraints:
    • intension
      • arithmetical expressions
      • relational expressions
      • logical expressions
    • extension
    • regular
    • mdd
    • allDifferent
    • allEqual
    • ordered (and lex)
    • sum
    • count
    • cardinality
    • minimum
    • maximum
    • element
    • channel
    • stretch
    • noOverlap
    • cumulative
  • extensive testing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.