GithubHelp home page GithubHelp logo

kianasun / xcsp3-cpp-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xcsp3team/xcsp3-cpp-parser

0.0 1.0 0.0 193 KB

XCSP3 Core Parser in C++

License: MIT License

CMake 0.57% C++ 99.43%

xcsp3-cpp-parser's Introduction

C/C++ parser for the CSP XML format version 3.0

(c) 2015 xcsp.org (contact xcsp.org)
(c) 2008 olivier.roussel at cril.univ-artois.fr

Introduction

The files in this archive contains a C++ parser for the XML format of CSP/WCSP instances named XCSP 3.0 (see http://xcsp.org).

This parser uses the libxml2 library which must be installed on your system

See http://xmlsoft.org/

This library is probably installed on most Linux platforms. Note that you'll need both the libxml2 and the libxml2-devel packages to compile your program.

The proposed parser reads the XML file in SAX mode. That means that each time an XML tag is read, the libxml2 library calls a function of the parser. In turn, the parser will decode the XML information and call a function of the solver to transmit the informations that were read.

The advantage of the SAX mode is that it doesn't use much memory. Its drawback is that it forces to read the information in the order of the XML file. In contrast, the DOM model would allow reading the informations in any order but would require to store the whole XML file in memory before the solver can grab any information.

Here's how the parser interfaces with the solver. The author of a solver writes an interface (a set of functions) which are called by the parser when it decodes a piece of information from the XML file (this is a callback). These interface functions are in charge of populating the data structures used by the solver. They don't have to cope with the XML details (only the parser does). This is in fact an instance of the Builder Design Pattern (http://www.developer.com/design/article.php/1502691)

The programmer simply calls the parser with the file to read and with a reference to the callback functions to use. The parser reads the file, decodes the information and calls the callback functions that create the solver data structures. Once the parser is done, the solver can start its quest of a solution.

Let's take an example to give a clear idea of how it can work:

  1. the solver calls the parser
  2. the parser reads the XML file, chunk by chunk
  3. when the parser reads the <instance> tag, it calls the solver callback's function beginInstance(). When the parser reads the </instance> tag, it calls the function endInstance().
  4. It does the same calls for tags variables, constraints, group, slide, block and objectives. These functions are not essentials. Their original implementations are empty.
  5. when the parser reads the <var> tag, the callback's function buildVariableInteger is called (depending if the domain is a range or not). You must override these two functions in order to create your own variables.
  6. the same occurs for each type of constraint, with the dedicated call to buildConstraintXXX where XXX is either Extension, Intension.... Note that all of these functions are surrounded and throw an exception if they are not overriden.
  7. Given an array of variables, a call to buildVariableInteger will occur for each element of the array
  8. Given a group of constraint, a call to the dedicated builConstraintXXX will occur for each arguments of the group (the same occurs for slide).

Note This parser uses std::regex. You need clang compiler or g++ with a version >= 4.9

xcsp3-cpp-parser's People

Contributors

pothitos avatar

Watchers

James Cloos avatar

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.