Giter VIP home page Giter VIP logo

cassowary.net's Introduction

Cassowary.net README

Cassowary.net [1] is a port of the Cassowary constraint solving toolkit [2] to the .NET platform. It is based on the Java version by Greg J. Badros, which in turn is based on the Smalltalk version by Alan Borning.

This fork of Cassowary.net initially began as a simple cleanup effort, refactoring the ported Java style code to a C# style of code. A new expression based constraint composition system has been added.

Nuget

The easiest way to use this fork is from the nuget package manager.

Status

I am not personally actively using this at the moment. I will accept PRs but I am unlikely to dedicate much time to fixing bugs. I would recommend using the far more powerful Z3 solver built by Microsoft instead. In my tests Z3 has shown itself to be generally faster than Cassowary at solving linear problems, whilst having the capacity to solve non-linear problems when required.

Composing Constraints

Creating complex constraints is very easy using the expression based extensions to the system:

var solver = new ClSimplexSolver();

solver.AddConstraint(a => a > 10);

This basic expression will create a constraint which operates on one variable, named "a", and adds a constraint that "a" must be greater than 10. Much more complex constraints than this can be created:

solver.AddConstraint((bl, br, wl, wr) => bl == wl && br == wr || br > 100);

Of course, it may not be convenient to include your variable names directly in your C# variable definitions, the above example is difficult to read because we have no idea what the definitions means. However if we rewrite it with meaningful names...

solver.AddConstraint((buttonLeft, buttonRight, windowLeft, windowRight) => buttonLeft == windowLeft && buttonRight == windowRight || buttonRight > 100);

...it becomes very long and tiresome. To solve this problem you can pass in your variable objects directly, and then bind them to temporary names:

var buttonLeft = new ClVariable("buttonLeft");
var buttonRight = new ClVariable("buttonRight");
var windowLeft = new ClVariable("windowLeft");
var windowRight = new ClVariable("windowRight");

solver.AddConstraint(
    buttonLeft, buttonRight, windowLeft, windowRight        // Pass in the variables here
    (bl, br, wl, wr) =>                                     // Bind them to temporary names in this expression
    bl == wl && br == wr || br > 100);                  // Define the constraints, using the temporary names
);

cassowary.net's People

Contributors

jozilla avatar martindevans avatar bazilshep 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.