GithubHelp home page GithubHelp logo

luhanzhen / xcsp3-rust Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 784 KB

The purpose of this library is to read XCSP files into rust constraint programming solvers.

License: MIT License

Rust 100.00%
constraint-optimisation-problem constraint-programming constraints parser parsing-library rust xcsp3

xcsp3-rust's Introduction

xcsp3-rust

xcsp3 xcsp3rust docs.rs MSRV License

Description

This lib is implemented by rust and is licensed under the MIT license.

The purpose of this library is to read XCSP files into rust constraint programming solvers.

You can learn about the semantics of XCSP3 through this site http://xcsp.org/.

I will keep improving this code to support more constraints and fix possible bugs.

If you have something to tell me, feel free to contact me.

Usage

Just add the following dependency to your project's Cargo.toml file:

[dependencies]
xcsp3-rust = "0.1.0"

The library is automatically built and statically linked to your binary.

Example

    fn main()
    {
        let xml_file = ".//instances//my-example.xml";
        let model = XcspXmlModel::from_path(xml_file).unwrap();
        let variable = model.build_variables();
        println!("variables:");
        for v in variable.iter() {
            println!("\t{}", v);
            match v {
                XVariableType::XVariableNone(_) => {}
                XVariableType::XVariableArray(_) => {}
                XVariableType::XVariableInt(_) => {}
                XVariableType::XVariableTree(_) => {}
            }
        }
        println!("constraints:");
        for c in model.build_constraints(&variable).iter_mut() {
            println!("\t{}", c);
            match c {
                XConstraintType::XConstraintNone(_) => {}
                XConstraintType::XExtension(_) => {}
                XConstraintType::XAllDifferent(_) => {}
                XConstraintType::XAllDifferentExcept(_) => {}
                XConstraintType::XInstantiation(_) => {}
                XConstraintType::XAllEqual(_) => {}
                XConstraintType::XOrdered(_) => {}
                XConstraintType::XRegular(_) => {}
                XConstraintType::XMdd(_) => {}
                XConstraintType::XIntention(_) => {}
                XConstraintType::XGroup(_) => {}
                XConstraintType::XSum(_) => {}
                XConstraintType::XMaximum(_) => {}
                XConstraintType::XMinimum(_) => {}
                XConstraintType::XElement(_) => {}
                XConstraintType::XSlide(_) => {}
                XConstraintType::XCount(_) => {}
                XConstraintType::XNValues(_) => {}
                XConstraintType::XCardinality(_) => {}
                XConstraintType::XChannel(_) => {}
                XConstraintType::XCumulative(_) => {}
                XConstraintType::XNoOverlap(_) => {}
                XConstraintType::XStretch(_) => {}
            }
        }
        println!("objectives:");
        for o in model.build_objectives(&variable).iter() {
            println!("\t{}", o);
            match o {
                XObjectivesType::XObjectiveNone(_) => {}
                XObjectivesType::Minimize(e) => match e {
                    XObjective::XObjectiveElement(_) => {}
                    XObjective::XObjectiveExpression(_) => {}
                },
                XObjectivesType::Maximize(e) => match e {
                    XObjective::XObjectiveElement(_) => {}
                    XObjective::XObjectiveExpression(_) => {}
                },
            }
        }
    }

Architecture Graph

main architecture

graph BT
A["XCSP(xml file)"] --serde--> B(XcspXmlModel)
B --parser--> C([XVariableSet])
B --parser--> D([XConstraintSet])
B --parser--> E([XObjectivesSet])
C --reader--> F[/example.rs/]
D --reader--> F
E --reader--> F

Loading

XVariableSet

graph LR
    C([XVariableSet]) -.->XVariableType(XVariableType)
    XVariableType -->  XVariableArray(XVariableArray)
    XVariableType -->  XVariableInt(XVariableInt)
    XVariableType -->  XVariableTree(XVariableTree)
    XVariableTree -.domain.->  XDomainInteger(XDomainInteger)
    XVariableInt -.domain.->  XDomainInteger
    XVariableArray -.domain.->  XDomainInteger
    XDomainInteger -.-> XIntegerType(XIntegerType)
    XIntegerType -->IntegerValue(IntegerValue)
    XIntegerType -->IntegerInterval(IntegerInterval)
    XIntegerType -->XIntegerSymbolic(XIntegerSymbolic)

Loading

XConstraintSet

graph LR
    D([XConstraintSet]) -.-> XConstraintType(XConstraintType)
    XConstraintType -->  XExtension(XExtension) -.scope.-> Scope(XVarVal)
    XConstraintType --> XAllDifferent(XAllDifferent)-.scope.-> Scope
    XConstraintType --> XAllDifferentExcept(XAllDifferentExcept)-.scope.-> Scope
    XConstraintType --> XInstantiation(XInstantiation)-.scope.-> Scope
    XConstraintType --> XAllEqual(XAllEqual)-.scope.-> Scope
    XConstraintType --> XOrdered(XOrdered)-.scope.-> Scope
    XConstraintType --> XRegular(XRegular)-.scope.-> Scope
    XConstraintType -->XMdd(XMdd)-.scope.-> Scope
    XConstraintType -->XIntention(XIntention)-.scope.-> Scope
    XConstraintType -->XGroup(XGroup)-.scope.-> Scope
    XConstraintType -->XSum(XSum)-.scope.-> Scope
    XConstraintType -->XMaximum(XMaxMin)-.scope.-> Scope
    XConstraintType -->XMinimum(XMaxMin)-.scope.-> Scope
    XConstraintType -->XElement(XElement)-.scope.-> Scope
    XConstraintType -->XSlide(XSlide)-.scope.-> Scope
    XConstraintType -->XCount(XCount)-.scope.-> Scope
    XConstraintType -->XNValues(XNValues)-.scope.-> Scope
    XConstraintType -->XCardinality(XCardinality)-.scope.-> Scope
    XConstraintType -->XChannel(XChannel)-.scope.-> Scope
    XConstraintType -->XCumulative(XCumulative)-.scope.-> Scope
    XConstraintType -->XNoOverlap(XNoOverlap)-.scope.-> Scope
    XConstraintType -->XNoOverlapKDim(XNoOverlap)-.scope.-> Scope
    XConstraintType --> XStretch(XStretch)-.scope.-> Scope
    Scope -->IntVar(IntVar is a variable)
    Scope -->IntVal(IntVal is a value)
Loading

XObjectivesSet

graph LR
    E([XObjectivesSet]) -.-> T(XObjectivesType)
%%    XVariableArray(XVariableArray)
    T --> Minimize(Minimize)
    T --> Maximize(Maximize)
    Minimize --> XObjective(XObjective)
    Maximize --> XObjective(XObjective)
    XObjective --> XObjectiveElement(XObjectiveElement)
    XObjective --> XObjectiveExpression(XObjectiveExpression)
Loading

License

MIT License

Author

luhan zhen

tip: Maybe my code is not the best, but I will keep improving it to better build our 'CP' community.

xcsp3-rust's People

Contributors

luhanzhen avatar

Stargazers

 avatar  avatar

Watchers

 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.