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

please help, how can i fix this multiplication error

回答済み

コメント

9件のコメント

  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    Could you please clarify what is the exact issue here?

    Looking at the \(\texttt{junk.lp}\) file, I can see all transmission constraints constructed as expected:

    R720: 0.5 genoutput[0,0] <= 10
    ...
    R744: 0.4 genoutput[1,0] <= 10
    ...
    0
  • Hussain Askar
    • Gurobi-versary
    • Conversationalist
    • First Question

    The issue is that this constraint is ignored. With transmission constraint and  without it, the code gives the same results. If this constraint was applied correctly, then our generator 1 output won't be 20 GW, we would see generators 5- 10 generate more than generators 1- 5. But that is not what is happening here. When I tried to see what the code gives if i multiply 0.5 by output [0,0] the code gives 0.5 removing the output/over writing instead of multiplying, I don't know how to fix this problem.

    0
  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    If you observe that your transmission constraints have no impact on the solution then you should double check all your other constraints. If you have an idea of what a correct solution point should look like, you could check the X attribute value of each variable and check each constraint by hand whether it behaves as expected.

    Currently all of your variables have a default lower bound of \(0\). You could try setting variable lower bounds to \(-\infty\).

    ngen = model.addVars(ntypes, nperiods, lb=-GRB.INFINITY, vtype=GRB.INTEGER, name="ngen")
    nstart = model.addVars(ntypes, nperiods, lb=-GRB.INFINITY, vtype=GRB.INTEGER, name="nstart")
    output = model.addVars(ntypes, nperiods, lb=-GRB.INFINITY, vtype=GRB.CONTINUOUS, name="genoutput")

    However, I don't know whether your problem is still valid.

    0
  • Hussain Askar
    • Gurobi-versary
    • Conversationalist
    • First Question

    I verified that all constraints are working as expected except the transmission constraint. When I checked by hand for period 0, the sum was 15.45 <= 10 which should not be valid but the code did not report any issues which means that something wrong is happening here. 

     

    When you check the results for output[0,0], the code gives 20 which is fine but when you multiply 0.5 * output [0,0], the code gives 0.5 . So the code is overwriting the output with the value of the constant we multiply it with at that constraint and that's why the code is reporting no issues because the sum of these small values will never exceed 10. 

     

    My question is that why it is not multiplying the constants with the variable output? The results clearly show that this constraint is being ignored.

     

    Also, what do you mean by not knowing whether my problem is still valid? I tried setting variable lower bounds to  ∞ and that affected all other constraints but not the transmission constraint which I'm working on.

    0
  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    When you check the results for output[0,0], the code gives 20 which is fine but when you multiply 0.5 * output [0,0], the code gives 0.5 . So the code is overwriting the output with the value of the constant we multiply it with at that constraint and that's why the code is reporting no issues because the sum of these small values will never exceed 10. 

    I am confused. Are you saying that the solution point found by Gurobi is an infeasible one? If yes, could you please point to the exact constraints and variable values at the optimal solution point which violate the particular constraint. I could not observe any of this when I executed your code (with and without negative lower bounds for your variables).

    In particular I am confused by the part

    but when you multiply 0.5 * output [0,0], the code gives 0.5 . So the code is overwriting the output 

    When do you multiply output[0,0] by 0.5? Which output is overwritten? Could you please elaborate further on this?

    Also, what do you mean by not knowing whether my problem is still valid? I tried setting variable lower bounds to  −∞ and that affected all other constraints but not the transmission constraint which I'm working on.

    It was just an idea since I don't know your model and its application. Thus, simply using negative lower bound for variables can completely change their meaning. For example, I don't know whether allowing for a negative \(\texttt{nstart}\) in your problem formulation makes sense. This is something you know better.

    0
  • Hussain Askar
    • Gurobi-versary
    • Conversationalist
    • First Question

    Hi Jaromil,

    The constraint ( Transmission constraint ) was created to do the following:

    • for period 0 : 0.5 * output [0,0] + 0.4 * output [1,0] + 0.3 * output [2,0] + 0.2 * output [3,0] + ... + (-0.4) * output [9,0] <= 10
    • for period 1 : 0.5 * output [0,1] + 0.4 * output [1,1] + 0.3 * output [2,1] + 0.2 * output [3,1] + ... + (-0.4) * output [9,1] <= 10
    • and so on for all 24 periods from 0 - 23

    Based on the output values the code is giving me, this constraint is not doing what I wanted.

     

    When do you multiply output[0,0] by 0.5? Which output is overwritten? Could you please elaborate further on this?

    • In jupyter notebook, in a new cell, I tried to just do the following: 0.5 * output [0,0] and the answer was 0.5 which didn't make sense for me because according to my code, output [0,0] = 20 and thus I expected to see 0.5 * output [0,0] = 10 not 0.5! 

           

    I hope this explains the issue

    0
  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    Hi Hussain,

    Thank you for clarifying, this helps a lot.

    The constraint ( Transmission constraint ) was created to do the following:

    • for period 0 : 0.5 * output [0,0] + 0.4 * output [1,0] + 0.3 * output [2,0] + 0.2 * output [3,0] + ... + (-0.4) * output [9,0] <= 10
    • for period 1 : 0.5 * output [0,1] + 0.4 * output [1,1] + 0.3 * output [2,1] + 0.2 * output [3,1] + ... + (-0.4) * output [9,1] <= 10
    • and so on for all 24 periods from 0 - 23

    Based on the output values the code is giving me, this constraint is not doing what I wanted.

    This is not what your constraint is doing right now because it is defined in a wrong way. The constraint should be defined as

    Line_Con = model.addConstrs(gp.quicksum(Line_Dfax[type] * output[type,period] for type in range(ntypes)) <= 10
                                for period in range(nperiods))

    In jupyter notebook, in a new cell, I tried to just do the following: 0.5 * output [0,0] and the answer was 0.5 which didn't make sense for me because according to my code, output [0,0] = 20 and thus I expected to see 0.5 * output [0,0] = 10 not 0.5! 

    This is because the object output[0,0] itself does now have a numerical value. To access the solution point value, you have to access the respective variable's X attribute 

    print(0.5 * output[0,0].X)
    0
  • Hussain Askar
    • Gurobi-versary
    • Conversationalist
    • First Question

    I'm really sorry, just by explaining the problem to you I realized what I was doing wrong.

    I think this solves it:

    Line_Con = model.addConstrs(gp.quicksum(output[type, period]*Line_Dfax[type]  for type in range(ntypes)) <= 10 for period in range(nperiods))

    0
  • Hussain Askar
    • Gurobi-versary
    • Conversationalist
    • First Question

    Thank you sir for your help! I appreciate it

    0

サインインしてコメントを残してください。