Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do we define an "objective function" and maximize or minimize it? #176

Open
trusktr opened this issue Jan 26, 2024 · 2 comments
Open

Comments

@trusktr
Copy link

trusktr commented Jan 26, 2024

I have a feeling this concept is implicit in the usage of Kiwi, but I'm new to this stuff, and wondering if you can help point it out, if in fact the API allows it.

I read the Cassowary paper (API very similar to Kiwi's),

https://cassowary.readthedocs.io/_/downloads/en/latest/pdf/

and it mentions that it is great for solving objective function min/maximization problems, however after that brief mention at the top of the doc, it no longer mentions "objective function" anywhere else.

Where exactly in that doc is the "objective function", and is it being minimized or maximized?

(I'm trying to figure it out for use in the TypeScript fork of kiwi, and I'd like to document these concepts more clearly if in fact they are doable).


In Google OR-Tools, there's actually an API for explicitly defining objective functions, with "objective" in the API naming:

https://developers.google.com/optimization/lp/lp_example#define_the_objective_function

// Maximize 3 * x + 4 * y.
MPObjective objective = solver.objective();
objective.setCoefficient(x, 3);
objective.setCoefficient(y, 4);
objective.setMaximization();
@trusktr trusktr changed the title How to we define an "objective function" and maximize or minimize it? How do we define an "objective function" and maximize or minimize it? Jan 26, 2024
@MatthieuDartiailh
Copy link
Member

Indeed in kiwi one cannot directly access the objective function. Kiwi attempts to satisfy all constraints and minimize the deviation for constraints with a non-required strength.

I am not sure how best to help you however. @sccolbert may have a clearer image of kiwi inner working than I do though.

@sccolbert
Copy link
Member

The "objective function" in kiwi is implicit.

Broadly, the objective function minimizes the error of non-required constraints, while simultaneously satisfying the required constraints.

For example: if x <= 0 but also x >= -50 | weak and x == 50 | weak, then we can guarantee that x will indeed be <= 0 and that x will tend towards +50 as much as is allowed from the other constraints. So in the absense of any other constraints, the "most optimal" solution to this problem is x = 0, because that's the best solution to the given constraints.

The 'objective function' is the amalgamation of all of these constraints in the system, no matter how many variables, provided they are all linearly related.

Your job as a library author is to present your problem-to-be-solved as a series of linear (in)equality constraints where the solution is the optimal balance of meeting the "required" constraints in full, and then getting as close as possible to the non-required constraints based on their weights.

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

No branches or pull requests

3 participants