@Override
  public void doPivot(Integer pivotHoriz, Integer pivotVert) {
    // { Preconditions
    assert (this.model.getConstraints().size() > 0) : "Cannot do pivot without constraints";
    assert (this.model.getObjfuncVariables().size() > 0) :
        "Cannot do pivot with an empty objective-function";
    assert (this.model.hasSolution()) : "An initial solution is needed by the pivot algorithm";
    // }

    Variable pivotVariable = this.model.getConstraint(pivotHoriz).findVariableById(pivotVert);
    BigDecimal pivotCoefficient = pivotVariable.getCoefficient();

    // ==> Update the constraint that contains the pivot
    // Get the variables for the new pivot constraint
    List<Variable> vars = new ArrayList<Variable>();
    ImmutableLinearConstraint pivotConstraint = this.model.getConstraint(pivotHoriz);
    for (Variable var : pivotConstraint.getVariables()) {
      vars.add(SmartVariable.createFromExistingId(var.getId(),
          BigDecimalUtil.divide(var.getCoefficient(), pivotCoefficient)));
    }
    // Update the pivot constraint
    pivotConstraint = DefaultImmutableLinearConstraint.create(vars, pivotConstraint.getSign(),
        BigDecimalUtil.divide(pivotConstraint.getConstantTerm(), pivotCoefficient));
    // Update the pivot constraint into the model
    Boolean pivotConstraintChanged = this.model.setConstraint(pivotHoriz, pivotConstraint);
    assert (pivotConstraintChanged) : "Pivot algorithm bug. Updated a non-existing constraint";

    // ==> Update the constraints that doesn't contain the pivot
    for (Integer idx = 0; idx < this.model.getConstraintsSize(); idx++) {
      ImmutableLinearConstraint constraint = this.model.getConstraint(idx);

      BigDecimal secondOp = constraint.findVariableById(pivotVert).getCoefficient();

      if (!idx.equals(pivotHoriz)) {

        for (Variable var : constraint.getVariables()) {
          BigDecimal firstOp = pivotConstraint.findVariableById(var.getId()).getCoefficient();
          BigDecimal factor = firstOp.multiply(secondOp);
          this.model.setConstraintVariable(idx, var.getId(), var.getCoefficient().subtract(factor));
        }
        BigDecimal firstOp = pivotConstraint.getConstantTerm();
        BigDecimal factor = firstOp.multiply(secondOp);
        this.model.setConstraintConstantTerm(idx, constraint.getConstantTerm().subtract(factor));
      }
    }

    // ==> Update the objective-function
    BigDecimal secondOp = this.model.getObjfunc().findVariableById(pivotVert).getCoefficient();
    for (Variable var : this.model.getObjfunc().getVariables()) {
      BigDecimal firstOp = pivotConstraint.findVariableById(var.getId()).getCoefficient();
      BigDecimal factor = firstOp.multiply(secondOp);

      this.model.setObjfuncVariable(var.getId(), var.getCoefficient().subtract(factor));
    }

    // ==> Update the base
    this.base.put(pivotHoriz, pivotVert);
    logger.info("The base is: " + this.baseToString());

    // ==> Update the solution
    Map<Integer, BigDecimal> varsValues = new HashMap<Integer, BigDecimal>();
    // Update the solution for the variables that are in the base
    for (Map.Entry<Integer, Integer> baseEntry : this.base.entrySet()) {
      Integer constraintIndex = baseEntry.getKey();
      Integer varId = baseEntry.getValue();
      ImmutableLinearConstraint constraint = this.model.getConstraint(constraintIndex);
      varsValues.put(varId, constraint.getConstantTerm().multiply(
          constraint.findVariableById(varId).getCoefficient()));
    }
    // Update the solution for the variables that aren't in the base
    for (Variable var : this.model.getObjfunc().getVariables()) {
      if (varsValues.get(var.getId()) == null) {
        varsValues.put(var.getId(), BigDecimal.ZERO);
      }
    }
    this.model.addSolution(this.model.getCurrentSolution().duplicate(null, varsValues, null));

    logger.info("The model is:\n" + this.model.toString());

  }