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

How convert GAMS to Gurobi?

回答済み

コメント

8件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three 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 why not try our AI Gurobot?.
  • Jaromił Najman
    • Gurobi Staff

    Hi John,

    You can construct the objectives by using the quicksum function and the setObjectiveN method.

    objes  = mdl.setObjectiveN(gp.quicksum(x[e,l] for e in es for l in load), 0, 1)
    obco2 = mdl.setObjectiveN(gp.quicksum(x[p,l]*CO2emission[p] for p in power for l in load), 1, 1)
    obcost = mdl.setObjectiveN(gp.quicksum(x[p,l]*cost[p] for p in power for l in load), 2, 1)

    mdl.write("myLP.lp")

    The write method writes a human-readable LP file which you can analyze and check whether your constructs are correct.

    Please note that you don't need additional objective function variables in Gurobi.

    You can find more details on how to work with multiple objectives in the documentation.

    Best regards,
    Jaromił

    0
  • John Raphy Karippery
    • Gurobi-versary
    • Investigator
    • Collaborator

    Hello Jaromił,

    Thank you so much for the replay. how to set model sense to objective.
    here motive of objective.

       objcost   'objective for minimizing cost in K$'
       objco2    'objective for minimizing CO2 emissions in Kt'

     

       objes     'objective for maximizing endogenous sources in GWh'

    objes is to maximize

     
    objes = mdl.setObjectiveN(quicksum(x[e,l] for e in es for l in load),GRB.MAXIMIZE, 0, 1)

    I got an error called

    GurobiError: Objective index must be non-negative


    variable X is a positive variable and it for 'production level of unit in load area in GWh';

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi John,

    It is not possible to set the optimization sense of individual objectives when working with multiple objectives. You can either minimize or maximize all objectives by setting the model's ModelSense attribute.

    If you want to minimize one objective and maximize the other, you can multiply the appropriate objective function by \(-1\).

    Best regards,
    Jaromił

    0
  • John Raphy Karippery
    • Gurobi-versary
    • Investigator
    • Collaborator

    Do you mean like this?


    objes = mdl.setObjectiveN(quicksum(x[e,l] for e in es for l in load)-1, 0, 1)
    0
  • Jaromił Najman
    • Gurobi Staff

    You are not multiplying by \(-1\) but subtracting \(1\) from the sum. What I mean is

    objes = mdl.setObjectiveN(quicksum(-1 * x[e,l] for e in es for l in load), 0, 1)

    Best regards,
    Jaromił

    0
  • John Raphy Karippery
    • Gurobi-versary
    • Investigator
    • Collaborator

    Hello

    I also need your help to convert to Gurobi. 

    ORD : Returns the relative position of an element in a set. Note that ord may be used only with one-dimensional, static, ordered sets. For more details, see section The Ord Operator.

    how to convert this syntex from GAMS?

    k1(k)$(ord(k) = 1) = yes;
    km1(k) = yes;
    km1(k1) = no;

    Thank you

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi John,

    You can get the index of an element in a list by using the index function, cf. the stackoverflow post Finding the index of an element in a list.

    There are very good Python tutorials available which might help you turning all the GAMS features into Python code.

    Best regards,
    Jaromił

    0

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