Code Monkey home page Code Monkey logo

Comments (6)

sccolbert avatar sccolbert commented on July 1, 2024

Can you please provide a reproducible test case. As small as possible preferably :)

Also, Kiwi should never return bad values, if it can't find a solution it should throw an unsatisfiable constraint exception. Are you perhaps eating an exception somewhere?

from kiwi.

SylvainCorlay avatar SylvainCorlay commented on July 1, 2024

Yes, I am trying to get a small example that triggers it. Will get back to you.

from kiwi.

starwing avatar starwing commented on July 1, 2024

@sccolbert Hi, I have found a inconsistent test, with the code below:

#include "kiwi.h"

#include <stdio.h>

using namespace kiwi;

int main(void)
{
    Variable xl("xl"), xm("xm"), xr("xr");
    Solver solver;

    solver.addConstraint(xm*2 == xl + xr);
    solver.addConstraint(xl + 10 <= xr);
    solver.addConstraint(xr <= 100);
    solver.addConstraint(xl >= 0);

    solver.updateVariables();
    printf("%g, %g, %g\n", xl.value(), xm.value(), xr.value());

    solver.addEditVariable(xm, strength::strong);
    solver.updateVariables();
    printf("%g, %g, %g\n", xl.value(), xm.value(), xr.value());

    solver.suggestValue(xm, 70);
    solver.updateVariables();
    printf("%g, %g, %g\n", xl.value(), xm.value(), xr.value());

    return 0;
}

this is my result:

test
90, 95, 100
0, 5, 10
40, 70, 100
Hit any key to close this window...

it should be 65, 70, 75, but not 40, 70, 100, the second constraint missing.

I have found this here, this is the examples in the Cassowary algorithm paper.

could give some help about this? I'm trying implement this algorithm in pure Lua language and meet this issue.

from kiwi.

sccolbert avatar sccolbert commented on July 1, 2024

@starwing

(40, 70, 100) is a solution to the problem, and so is (65, 70, 75). There may also be more valid solutions.

The problem as-written is underconstrained, so kiwi is just going to pick one of the solutions. Which one is picked is more or less random.

If your second constraint was == instead of <=, or if you added another constraint to pin one of the values, you would get your desired solution.

Kiwi appears to be behaving as designed here.

from kiwi.

starwing avatar starwing commented on July 1, 2024

@sccolbert okay, my fault :( I just realize this fact, sorry for noise

from kiwi.

MatthieuDartiailh avatar MatthieuDartiailh commented on July 1, 2024

Closing as it appears to be normal

from kiwi.

Related Issues (20)

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.