Skip to main content

Variables return wrong values

Answered

Comments

4 comments

  • Official comment
    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?.
  • Alison Cozad
    • Gurobi Staff

    I solved your model and it looks like all variables are equal to zero except for the two in your printout:

    C131 7000
    C257 1.8587619047619048e+03

    It looks like you are probably using Model.printAttr('X') to view your variable solution values.  For brevity, this function prints all non-zero variable values.  This is why you are only seeing the two, non-zero values --- rather than the full list of variables.

    You can confirm by viewing the values of your full variable list.  This can be done in a few different ways.  My two other favorites are:

    1. Write a SOL file by running the following after you optimize the model:
      m.write('results.sol')
    2. Creating a dataframe with the results by running the following after you optimize:
      import pandas as pd

      # Store Variable info
      varInfo = [(v.varName, v.X, v.LB, v.UB) for v in m.getVars() ]
      df = pd.DataFrame(varInfo)
      df.columns=['Variable Name','Solution Value', 'LB','UB']

     

    0
  • Nelly V
    • Gurobi-versary
    • First Comment
    • First Question

    @..., thank you for your response. Yes makes sense. Any suggestion why they are zero? Because they shouldn't be! Thank you very much

    0
  • Alison Cozad
    • Gurobi Staff

    Can you tell me a bit about why you would expect more to be non-zero?  Are there specific variables you would expect to be non-zero?

    From what I can tell, within each of the variable tupledicts there is no differentiation between variables.  This can lead to some redundancy. 

    For example, let's look at the \(\texttt{allocList}\) tupledict.  Each one of the 100+ \(\texttt{allocList}\) variables, has the same objective coefficient: -1.  Each of the \(\texttt{allocList}\) variables participates in two constraints, again each with the same coefficient:

    m.addConstr((allocList.sum() <= 7000), name='demandConstraints')
    m.addConstr(((allocList.sum()*0.69) +
    (ncList.sum()*105) +
    (rn.sum()* maxRunTime*0.70) +
    (rn.sum()* 10000)
    <= budget), name='budgetConstraints')

    Lastly, there are no upper or lower bounds on any of the variables in the \(\texttt{allocList}\) list.  So, as far as the math program is concerned all of the \(\texttt{allocList}\) variables are identical.  The only thing that limits them is the demand constraint.  Therefore, the following solution values of \(\texttt{allocList}\) would all be equivalent:

      Solution 1 Solution 2 Solution 3
    allocList[0,0]           7,000                -             1,000
    allocList[0,1]                -             7,000           1,000
    allocList[0,2]                -                  -             1,000
    allocList[0,3]                -                  -             4,000
    Total           7,000           7,000           7,000

    This means that there could be MANY values of \(\texttt{allocList}\) that would satisfy the constraints and get the same objective.  This makes me think there is something missing from your model that will lead to a solution that is a bit more realistic and closer to what you would expect.  This could include using your three \(\texttt{Select}\) binary variables. Or, it may mean creating constraints that are associated with some of your unused constants like \(\texttt{capacityToStorePerGP}\), \(\texttt{capacityTOStorePerHospital}\), \(\texttt{nurse_ratePerDay}\), and \(\texttt{nurse_max}\).

    0

Post is closed for comments.