メインコンテンツへスキップ

Fraction with quadratic numerator as objective function

回答済み

コメント

7件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support.
  • Maliheh Aramon
    • Gurobi Staff

    Hi Tobias, 

    To model a fractional expression like \(\frac{x}{y}\) with \(x\) and \(y\) being quadratic and linear expression, respectively, you need to define an auxiliary variable \(z\) where \(z = \frac{x}{y}\).

    You can then have:

    \[\begin{align} & \min  ~~z \\ \notag & \mbox{s.t:}~~  zy = x \end{align}\]

    Best regards,

    Maliheh

    1
  • Nipun Tulsian
    • First Comment

    How can we model this constraints?

    0
  • Marika Karbstein
    • Gurobi Staff

    Can you give more details about what exactly is unclear to you?

    0
  • Nipun Tulsian
    • First Comment

    I am trying to solve f(x) = (xTAx)/B^Tx, so basically a quadratic/linear. To solve this I used the following code:                        m = gp.Model("Fractional model", env=env)
                       m.Params.NonConvex = 2

                       x = m.addMVar(len(B), lb=-0.1, ub=0.1, vtype=GRB.CONTINUOUS, name="x")
                       y = m.addVar(lb = -1000 , ub = 1000 ,vtype = GRB.CONTINUOUS, name = 'y')

                       denominator = B @ x
                       numerator = x @ A @ x

                       m.addConstr(y * denominator == numerator, name="Auxillary Constraint")
                       m.setObjective(y , gp.GRB.MINIMIZE)

                       m.optimize()

    I am running the above code on multiple datasets, for some I am able to get values for x but for many datasets it gives nan values for output. If I am keeping y unbounded then for all datasets its coming nan. Can you please help on how to overcome this problem

     

    0
  • Marika Karbstein
    • Gurobi Staff

    Does it really show “nan” or are the x values simply 0? 
    Please note that the default lower bound for all variables created in Gurobi is 0.

    I would recommend to write and check the LP-file. You can use model.write("Test.lp") before calling optimize.
    Does the LP file represent the model you want to solve?

    0
  • Nipun Tulsian
    • First Comment

    Yes it shows all nan for variables we are trying to optimize. I will check the LP file

    0

投稿コメントは受け付けていません。