Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.

Objective function is unbounded in optimize #21

Open
msqaddura opened this issue Mar 24, 2017 · 3 comments
Open

Objective function is unbounded in optimize #21

msqaddura opened this issue Mar 24, 2017 · 3 comments

Comments

@msqaddura
Copy link

msqaddura commented Mar 24, 2017

I have currently passed by a weird bug in VFL and I think that it is not just something that I am doing wrong. The issue appears when I try to maintain aspect ratio of a subview and it gives me this error :
"Objective function is unbounded in optimize"

using vfl below :

let evf= [
    "H:|~[car(<=80%)]~|",
    "V:|~[car(<=50%)]~|",
    "H:|~[car(car.height*1.531)]~|",
    "V:|~[car(car.width/1.531)]~|"
] 

Applied to these 2 snippets :

Snippet 1: Throws an error

//Snippet 1 : Erroneous Code
let layoutView = new AutoLayout.View( {
            constraints: AutoLayout.VisualFormat.parse( evfl ,{extended: true}), 
            width : 2000,   //<--- it is 2000  here         
            height : 1400,          
            spacing: 0   
        });

Snippet 2: Works fine, no error

//Snippet 2 : Fine Code
let layoutView = new AutoLayout.View( {
            constraints: AutoLayout.VisualFormat.parse( evfl ,{extended: true}), 
            width : 1000,  // <--- it is 1000 now     
            height : 1400,          
            spacing: 0   
        });
//it even still works fine when I change its size later, to the latter width of 2000
layoutView.setSize(2000,1400)

I dont know if you use common libraries as with react-gss but they have same issue as well.
petehunt/react-gss#5

Thanks in advance

@IjzerenHein
Copy link
Owner

IjzerenHein commented Mar 26, 2017

Hi, I've looked at your EVFL and it contains several conflicting constraints. The first two lines are fine, but line 3 and 4 contain conflicting relationships.

Conflict 1:

  • Both lines 1/2 and 3/4 seem to want to center the content. This may lead to conflicts in forms of miniscule rounding errors as you described. You should have only 1 centering rule per dimension.

Conflict 2:

  • The aspect-ratio rule is defined twice (once by line 3 and again in line 4). Again, this leads to conflicting constraints. And in this case it may also expose itself in the form of a rounding problem. As a rule of thumb you should write your (E)VFL in such a way that it is completely unambiguous to calculate.

As for a fix, here are two solutions that would fix the problem (they are identical but use different syntaxes)

H:|~[car(<=80%)]~|
V:|~[car(<=50%)]~|
C:car.width(car.height*1.531)

Or even shorter:

H:|~[car(<=80%,car.height*1.532)]~|
V:|~[car(<=50%)]~|

That being said... I've seen situations where the order of the constraints can cause problems. Sometimes re-ordering the constraints fixes the problem. This lies in the underlying cassowary/kiwi constraint solver algorithm.

Hope that helps!

@msqaddura
Copy link
Author

msqaddura commented Apr 4, 2017

Hi, I already tried different variations including the mentioned above, all gave same error.
Only changing start width is helping me out but that is more than fine for me

Thanks for the hints though, they are extremely useful and precise.

@IjzerenHein
Copy link
Owner

Alright, well glad that was helpful and that you can at least workaround the issue.
Cheers

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants