Fraction with quadratic numerator as objective function
回答済みHi all,
I am currently trying to implement the following expression as objective function to my model (a, b being vectors of constant values):

I found out that I could construct the first part of the numerator as GRBQuadExpr, but subsequently I figured I could just express the second part of the numerator and the denominator as GRBLinExpr and add the pieces together - and failed to do so. Moreover, there is no "/" operator defined for GRBQuadExpr and GRBLinExpr, thus I am wondering if Gurobi has the means to construct such an expression and add them to models. Is there a predefined way to create fractional expressions or a common workaround that allows to use this expression or an abstraction of it?
Thanks in advance for any help, enjoy the holidays.
Best regards,
Tobias Tillipaul
-
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 -
How can we model this constraints?
0 -
Can you give more details about what exactly is unclear to you?
0 -
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 = 2x = 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 @ xm.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 problem0 -
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 -
Yes it shows all nan for variables we are trying to optimize. I will check the LP file
0
サインインしてコメントを残してください。
コメント
6件のコメント