jmjrawlings / minizinc.net Goto Github PK
View Code? Open in Web Editor NEWMiniZinc ↔ .NET
License: Other
MiniZinc ↔ .NET
License: Other
MRE:
record(int: a, int: b): x;
constraint x.a = 1;
The --json-stream
solution messages contain dzn syntax of the solution variables.
While the full model parser could certainly handle this we should instead make a specialised parser optimised for only these "name = expr" assignments.
Parsing dzn from file/string is worthwhile
There is a time limit command line argument MiniZinc but we should also allow CancellationToken
to support instance where, for example, a GUI user wants to cancel a solve in progress.
This probably replaces the need to use the CLI arg entirely as it is much more flexible.
client.Solve
fails when solving a model with an included .mzn
file.
We need to either update include
statements to point to an absolute filepath, or more appropriately just copy the included model into the working directory
Example in record_var_ite.mzn
For instance record
tests should only run when client is v2.7.*
We need the capabilty to combine or merge two or more separate Models
.
This is a generally useful thing to be able to do, but more specifically it would provide a direct way to handle include
statements. We could simply Model.parseFile
the included mzn, then combine the two models.
Obvious error cases here are binding conflicts between the two models so some options are required:
Consider the two:
array[1..3] of record(var bool: a): x;
array[1..3] of var record(bool: b): y;
Only the second example would have Inst = Inst.Var
in the AST.
We want this information at the top level to correctly identify decision variables without having to traverse the whole ast.
A client integration test would be the following:
Currently we strip out line and block comments before feeding the normalised source into the parser. It would be better to do it all in one parse, now that I have a better handle on creating low level parsers it should be fairly straightforward.
Different solver backends have different features and flags. It would be nice to surface these in a native way so the user can avoid dealing with command line flags. Something like GecodeClient :> IMiniZincClient
would be great.
Knowing what statistics are returned by which solver is very valuable as well, so a client should be strong typed on its inputs and outputs.
Models solved using the solver specific client would naturally have the --solver
flag appended.
We should aim for gecode
, cbc
and chuffed
for a v1.0 release.
There are quite a few things to take care of before solving a model:
par
variables must all have been assignedvar
solution variables.mzn
fileTo separate concerns a bit better we should perform the above in a compilation step, and that way the various solve
methods can operate on a nicely type CompiledModel
Currently we feed models through the parseComments
function to strip them of all comments before proceeding to the main parser. This is error prone (eg: it doesn't properly handle '%' inside of quoted string). It also means we are iterating over each file twice which is not ideal. Handling of comments should be integrated directly into the fparsec parser, possibly through some custom whitespace parser
Included models that are part of the standard library eg: "globals.mzn" do not need to be saved alongside our generated model so we need a way of identifying them
Given the minizinc types from the AST we want to translate directly to .NET types where possible. Technically we could implement our own algebra on top of the AST but this seems like total overkill.
Best case scenario here is being able to directly convert 1d/2d array etc to .NET array types and back again.
for models reference via the include statement eg: includes "battleships.mzn"
the parsing process should be able to follow these links if desired.
This is an important feature as it is the primary means of composition in minizinc
I would like to know the performance characteristics of the parser so any code changes can have their effect on performance quantified. I also want insight into any bottlenecks to focus on.
The usual suspects are of interest:
parse a model
encode the model
parse it again
models should be equivalent
If we roundtrip from Mzn -> Model -> Mzn -> Mzn, we need a way to determine if the models are equivalent. String comparison is not a good option, some sort of comparison between AST seems necessary.
tuple(int, float) ++ tuple(bool): con1 ::output = (1, 2.0) ++ (true,);
We should just flatten the above into a tuple(int, float, bool) = (1, 2.0, true)
to avoid unnecessary complexity in the Expr
union
Included in the test specs from the official repository there are solutions and expected results. These are perfect test cases if we can parse the comments properly.
Example:
/***
!Test
expected:
- !Result
solution: !Solution
a:
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
- [0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0]
- [0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0]
- [0, 2, 0, 0, 0, 1, 0, 0, 3, 0, 0]
- [0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0]
- [0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0]
- [0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0]
- [0, 1, 0, 0, 0, 0, 1, 2, 3, 4, 0]
- [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0]
- [0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0]
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
col_sums: [4, 0, 3, 2, 2, 2, 1, 4, 2]
row_sums: [2, 2, 3, 2, 2, 1, 5, 1, 2]
***/
A model integration test is the following pseudocode:
model1 = parse(input)
string1 = encode(model)
model2 = parse(string1)
string2 = encode(model2)
assert model1 == model2
assert string1 == string2 (unlikely to pass, optional)
MRE:
array[Index, Index, Index] of int: matrix = [| | | |];
Give the model AST we want to know which variable have already been assigned or which variable still need assignment. Those variables requiring assignment becomes parameters for the model
Serialize a model as an Mzn string
Currently the model combines declare
and assign
items in a global context. This will not work if, for instance, varaible X is declared on the top level and then assigned inside of a let block. That would erroneously be a conflicted binding.
Not sure how to do this honestly a bit of research required
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.