title: How to get the indices of the optimal basis using Gurobi through a C++ code
body: <p>I am calling Gurobi through a c++ program to solve a linear program and I need to extract the indices of the optimal base.</p>
  <pre><code>#include &quot;gurobi_c++.h&quot;
  #include &lt;stdlib.h&gt;
  using namespace std;
  #include&lt;vector&gt; 
  
  int
  main(int   argc,
       char *argv[])
  {
    try {
      GRBEnv env = GRBEnv();
      GRBModel model = GRBModel(env);
  
      // Create variables
  
      GRBVar x1 = model.addVar(0.0, GRB_INFINITY , 0.0, GRB_CONTINUOUS, &quot;x1&quot;);
      GRBVar x2 = model.addVar(0.0, GRB_INFINITY , 0.0, GRB_CONTINUOUS, &quot;x2&quot;);
  
      // Set objective
  
      // model.setObjective(4 * x1 + 6 * x2, GRB_MAXIMIZE);
      model.setObjective(2 * x1 - 5 * x2, GRB_MAXIMIZE);
  
      // Add constraints
  
      model.addConstr(2 * x1 + 3 * x2 &lt;= 30, &quot;c0&quot;);
  
      model.addConstr(4 * x1 - 9 * x2 &lt;= 0, &quot;c1&quot;);
  
      model.addConstr(x1 + x2 &gt;= 5, &quot;c2&quot;);
  
      // Optimize model
  
      model.optimize();
  
      //get the indices of the optimal base
      int nbColumns = 3;
      int nbLines = 2;
      int * bhead = (int *) malloc (nbLines); 
       for (int i = 0; i &lt; nbLines; ++i)
      {
      bhead[i] = -1;
      }
      
  
      GRBModel *p_model = &amp;model;
  
      int b = GRBgetBasisHead(p_model, bhead);
  
      cout&lt;&lt;&quot;base 1&quot;&lt;&lt;bhead[0]&lt;&lt;endl;
      cout&lt;&lt;&quot;base 2&quot;&lt;&lt;bhead[1]&lt;&lt;endl;;
      cout&lt;&lt;&quot;base 3&quot;&lt;&lt;bhead[2]&lt;&lt;endl;
  
    } catch(GRBException e) {
      cout &lt;&lt; &quot;Error code = &quot; &lt;&lt; e.getErrorCode() &lt;&lt; endl;
      cout &lt;&lt; e.getMessage() &lt;&lt; endl;
    } catch(...) {
      cout &lt;&lt; &quot;Exception during optimization&quot; &lt;&lt; endl;
    }
  
    return 0;
  }
  </code></pre>
  <p>I get an error when I try to use <code>GRBgetBasisHead</code> which is defined in the C API, the error is:</p>
  <pre><code>error: cannot convert ‘GRBModel*’ to ‘GRBmodel* {aka _GRBmodel*}’ for argument ‘1’ to ‘int GRBgetBasisHead(GRBmodel*, int*)’
  </code></pre>
  <p>Because in C++ API the models are constructed using <code>GRBModel</code> and in C API the models are constructed using <code>GRBmodel</code>. In the other hand, there is <code>VBasis</code> that gives the status of a variable in the current basis, but in this case we need to test the status of all the variables to find the indices of the optimal base. My question is: is there a way to get directly the indices of the optimal base?</p>