title: c++ cplex access current solution to add constraint
body: <p>i am trying to solve a LP-model in CPLEX using C++ and Concert Technology.</p>
  
  <p>I want to implement constraints (the subtour elimination constraints, to be more specific) that needs to query the value of two of my variables in the current solution: 
  The variable array xvar is indicating the edges, yvar is representing the nodes.</p>
  
  <p>I implement these constraints by solving n (= number of nodes) Min-Cut-Problems on a modified graph, which is constructed by adding an artificial source and an artifical sink and connect these to every node of the original graph. </p>
  
  <p>From what i've read so far, do i need a lazy constraint or a callback or none of this?</p>
  
  <p>This is where i create the model and get it solved, access the values of the variables in the solution etc:</p>
  
  <pre><code>    // Step 2: Construct the necessary CPLEX objects and the LP model
  IloCplex solver(env);
  
  std::cout&lt;&lt; "Original Graph g: " &lt;&lt;std::endl;
  std::cout&lt;&lt; net.g() &lt;&lt;std::endl;
  MCFModel model(env, net);
  
  
  // Step 3: Load the model into cplex and solve
  solver.extract(model);
  solver.solve();
  
  // Step 4: Extract the solution from the solver
  if(solver.getStatus() != IloAlgorithm::Optimal) throw "Could not solve to optimality!";
  IloNumArray xsol ( env, net.g().nEdges() );
  IloNumArray ysol ( env, net.g().nNodes() );
  IloNumArray rsol ( env, net.g().nGroups() );
  IloNumArray wisol ( env, net.g().nGroups() );
  IloNum ksol;
  NumMatrix wsol ( env, net.g().nGroups());
  
  for(IloInt i = 0; i &lt; net.g().nGroups(); i++){
  wsol[i] = IloNumArray( env, net.g().nGroups() );
  }
  
  solver.getValues(xsol, model.xvar());
  solver.getValues(ysol, model.yvar());
  solver.getValues(rsol, model.rvar());
  solver.getValues(wisol, model.wivar());
  ksol=solver.getValue(model.kvar());
  
  for (IloInt i = 0; i &lt; net.g().nGroups(); i++){
      wsol[i] = wisol;
  }
  
  // Step 5: Print the solution.
  </code></pre>
  
  <p>The constraint, i need the current values of the variables xvar and yvar for, is created here:</p>
  
  <pre><code>    //build subset constraint y(S) -x(E(S))&gt;= y_i 
      void MCFModel::buildSubsetCons(){
      IloExpr lhs(m_env);
      IloCplex cplex(m_env);
      IloNumArray xtemp ( m_env, m_net.g().nEdges() );
      IloNumArray ytemp ( m_env, m_net.g().nNodes() );
  
      std::vector&lt;Edge&gt; mg_twin;
      std::vector&lt;int&gt; mg_weights;
      int mg_s;
      int mg_t;
      SGraph mgraph;
      std::vector&lt;int&gt; f;
      int nOrigEdges = m_net.g().nEdges();
      int nOrigNodes = m_net.g().nNodes();
  
  
      cplex.getValues(xtemp, m_xvar);
      cplex.getValues(ytemp, m_yvar);
  
      mgraph = m_net.g().mod_graph();
      mg_s = mgraph.nNodes()-1;
      mg_t = mgraph.nNodes();
  
      std::cout&lt;&lt;"modified graph:"&lt;&lt;std::endl;
      std::cout&lt;&lt;mgraph&lt;&lt;std::endl;
  
      // fill the weight of original edges with 1/2*x_e
      foreach_edge(e, m_net.g()){
        mg_weights.push_back((xtemp[e-&gt;idx()])/2);
      }
      // fill the weight of the edges from artificial source with zero
      for(int i=0; i&lt;m_net.g().nNodes(); i++){
        mg_weights.push_back(0);
      }
  
      // fill the weight of the edges to artificial sink with f(i)
      // first step: calculate f(i):
      //f.resize(m_net.g().nNodes());
      foreach_node(i, m_net.g()){
      foreach_adj_edge(e, i, m_net.g()){
        f[i] = f[i] + xtemp[e-&gt;idx()];
      }
      f[i] = (-1)*f[i]/2;
      f[i] = f[i] + ytemp[i];
      }
      // second step: fill the weights vector with it
      for(int i=0; i&lt;m_net.g().nNodes(); i++){
        mg_weights.push_back(f[i]);
      }
  
      // calculate the big M = abs(sum_(i in N) f(i))
      int M;
      foreach_node(i, m_net.g()){
          M = M + abs(f[i]);
      }
  
      // Build the twin vector of the not artificial edges for mgraph
      mg_twin.resize(2*nOrigEdges + 2*nOrigNodes);
  
      for(int i=0; i &lt; nOrigEdges ; ++i){
        mg_twin[i] = mgraph.edges()[nOrigEdges + i];
        mg_twin[nOrigEdges + i] = mgraph.edges()[i];
      }
  
  
      //Start the PreflowPush for every node in the original graph
        foreach_node(v, m_net.g()){
      // "contract" the edge between s and v
      // this equals to higher the weights of the edge (s,v) to a big value M
      // weight of the edge from v to s lies in mg_weights[edges of original graph + index of node v]
      mg_weights[m_net.g().nEdges() + v] = M;
  
      //Start PreflowPush for v
      PreflowPush&lt;int&gt; pp(mgraph, mg_twin, mg_weights, mg_s, mg_t);
      std::cout &lt;&lt; "Flowvalue modified graph: " &lt;&lt; pp.minCut() &lt;&lt;      std::endl;
      }
    }
  </code></pre>
  
  <p>The Object pp is to solve the Min-Cut-Problem on the modified graph mgraph with artificial source and sink. The original graph is in m_net.g().</p>
  
  <p>When i compile and run it, i get the following error:</p>
  
  <pre><code>    terminate called after throwing an instance of 'IloCplex::Exception'
      Aborted
  </code></pre>
  
  <p>It seems to me, that it is not possible to access the values of xvar and yvar like this? 
  I do appreciate any help since i am quite lost how to do this.
  Thank you very much!!</p>