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

It should be able to have constraints on the attribute being optimized #21

Closed
JWally opened this issue Oct 30, 2015 · 7 comments
Closed
Assignees

Comments

@JWally
Copy link
Owner

JWally commented Oct 30, 2015

I want solver to be able to handle a use pattern like this:

I want to use as few {{x}} as possible, but we need
at least {{y}} there because of regulations. What
is the least number of {{x}} I can get away with
using?

Right now, if an attribute has a constraint on it and is being optimized the constraint gets ignored. An easy work-around would be something like this:

  1. Check to see if the model has any constraints using the same attribute as the optimize property.
  2. For each variable in the model, add a new attribute (call it fake- or something) and give it the same value as the attribute being constrained
  3. add a new constraint named fake or something (see step 2). Copy the old constraint to this new one
  4. Delete the old constraint
  5. Solve
  6. Solve
@JWally JWally self-assigned this Oct 30, 2015
@bchevalier
Copy link
Collaborator

Can you give an example of a problem that is not solved correctly? And what you expect the result to be?

Sent from my iPhone

On 2015/10/30, at 12:35, Justin Wolcott notifications@github.com wrote:

I want solver to be able to handle a use pattern like this:

I want to use as few {{x}} as possible, but we need
at least {{y}} there because of regulations. What
is the least number of {{x}} I can get away with
using?

Right now, if an attribute has a constraint on it and is being optimized the constraint gets ignored. An easy work-around would be something like this:

Check to see if the model has any constraints using the same attribute as the optimize property.
For each variable in the model, add a new attribute (call it fake- or something) and give it the same value as the attribute being constrained
add a new constraint named fake or something (see step 2). Copy the old constraint to this new one
Delete the old constraint
Solve
Solve

Reply to this email directly or view it on GitHub.

@JWally
Copy link
Owner Author

JWally commented Oct 30, 2015

{
      "name": "Computer Problem",
      "optimize": "profit",
      "opType": "max",
      "constraints": {
          "cost": {
              "max": 70000
          },
          "size": {
              "max": 1000
          },
          "profit": {
            "max": 65000
          }
      },
      "variables": {
          "computer": {
              "size": 12,
              "cost": 1000,
              "profit": 1000,
              "computer": 1
          },
          "printer": {
              "size": 8,
              "cost": 300,
              "profit": 350,
              "printer": 1
          }
      }
    }

Should be 65,000;
Returns 71818.18

Easy solution would be to make the model go from that (above) to this (below):

{
      "name": "Computer Problem",
      "optimize": "profit",
      "opType": "max",
      "constraints": {
          "cost": {
              "max": 70000
          },
          "size": {
              "max": 1000
          },
          "random-number": {
            "max": 65000
          }
      },
      "variables": {
          "computer": {
              "size": 12,
              "cost": 1000,
              "profit": 1000,
              "computer": 1,
              "random-number": 1000
          },
          "printer": {
              "size": 8,
              "cost": 300,
              "profit": 350,
              "printer": 1,
              "random-number": 350
          }
      }
    }

which yields 65,000

Its late here and I could easily be doing something wrong or overlooking something.

Are you ok with this functionality?
What are your thoughts on the method I'm suggesting to do it? Its pretty straight forward, and I could pick it up in src/main; or have another module that runs validations and clean-up on the model?

@bchevalier
Copy link
Collaborator

Ah i see, what you are trying to do is possible with the new weighting functionality on constraints. You could specify a constraint ´´´profit: { equal: 65000, weight: 1 }´´´ and remove the objective. The issue is that you might obtain a value for profit a little higher than 65,000 (if the constraint is not satisfied, you might be above as well as below the constraint). Do you have any use case for this functionality? It seems strange to limit the value of the function to optimize.

Another possible way to solve it, when Quadratic Optimization is possible would be to have the following objective function: ´´´min (1000_computer + 350_printer - 65000)^2´´´.

The problem with QP (quadratic programming) is that it does not seem compatible with the current json model format.

@JWally
Copy link
Owner Author

JWally commented Oct 30, 2015

I'm trying to think of a not-completely-contrived word problem for this and can't. I was tinkering around with the issue of solving multi-objective problems and when playing around with it, noticed that if I was minimizing an objective with a min constraint; the min constraint was ignored; which isn't what I was expecting.

Out of curiosity, what's incompatible with the JSON model format? The exponents?

It might be a less than ideal situation, but what if you expected a model that looked like this:

{
      "name": "Computer Problem",
      "optimize": "profit^2",
      "opType": "max",
...
    "variables": {
        "pizza^2": {"onion": 1, "cheese": .....}
    }
}

or this:

{
      "name": "Computer Problem",
      "quad-optimize": "profit^2",
      "opType": "max",
...
    "quad-variables": {
        "pizza": {...}
    }
 }

I'm not familiar with quadratic programming problems. Do you have an example a simple one? Simple like this:

min: x + y
s.t.
2x + 3y >= 3;
x - y >= 9

@bchevalier
Copy link
Collaborator

An example of QP:

min: x * x
s.t.
x >= 3;

or

min: x * y
s.t.
x + y >= 3;

or

min: (x - 5) * y
s.t.
x + y >= 3;

Basically any problem where there is at least one occurence of exactly two variables being multiplied in the objective function and no occurence of more than two variables being multiplied. All the constraints should remain linear.

@JWally
Copy link
Owner Author

JWally commented Oct 30, 2015

what if you did something like this:

{
      "optimize": ["x","y"],
      "opType": "min",
      "constraints": {
        "apple": {"min": 3}
     }
     "variables": {
        "apple": {"x": 1, "y": 1}
    }
}

where anything in the "optimize" array (or create a new property..."quad-opt") is being multiplied. This would work on your first 2 examples. The last example, I'm not sure how to set it up; but I wouldn't know how to set it up as a linear program if the function were `x-5+y``.

@JWally
Copy link
Owner Author

JWally commented Nov 3, 2015

initial issue was solved with my latest commit.
Closing.

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

2 participants