Esempio n. 1
0
Eigen::VectorXf Simplex::run() {
	int piv_col, piv_row;
	while(1){
		piv_col = findPivotColumn();
		//std::cout << " CHOIX PIVOT " << std::endl;
		//std::cout << " simplexe run piv_col : "<< piv_col << std::endl;
		if(piv_col < 0)
		{
			//std::cout<< " STOP " << std::endl;
			getBest(); // optimal
			return best;
		}
		piv_row = findPivotRow(piv_col);
		//std::cout << " simplexe run piv_row : " << piv_row << std::endl;

		if(piv_row < 0)
		{
			//std::cout << " Pas de solution" << std::endl;
			break; //caca
		}
		//std::cout << " val pivot : " << tab(piv_row,piv_col);
		//std::cout << " " << std::endl;
		pivot(piv_row, piv_col);
		//std::cout << tab << std::endl;
	}
	return best;
}
Esempio n. 2
0
int Simplex::simplex() {
    if (SIMPLEX_DEBUG) fprintf(stderr, "Simplex step:\n");
    if (SIMPLEX_DEBUG) printObjective();
    if (SIMPLEX_DEBUG) printTableau();

//	fprintf(stderr, "Objective = %.6f\n", optimum());

//	printTableau(true);

//	checkObjective2();

    if (!findPivotRow()) return SIMPLEX_OPTIMAL;

//	fprintf(stderr, "pivot row = %d\n", pivot_row);

    regeneratePivotRow();

//	checkObjective2();

//	if (!findPivotCol()) {
    if (!findPivotCol2()) {
        mip->unboundedFailure();
        return SIMPLEX_UNBOUNDED;
    }


//	fprintf(stderr, "pivot col = %d\n", pivot_col);

    pivot();

    simplexs++;

//	printB();

//	printTableau(true);

//	checkBasis();

//	printObjective();

//	if (SIMPLEX_DEBUG) printTableau();

//	exit(0);

    // If bound is already good enough to cause failure, return
    if (EARLY_TERM && (int) ceil(optimum()) > mip->objVarBound()) return SIMPLEX_GOOD_ENOUGH;

    return SIMPLEX_IN_PROGRESS;
}
Esempio n. 3
0
bool PSLQ::solve(UINT maxDigits) {
  const BigReal       maxNorm = rSqrt(sqr(e(1,maxDigits+1)-1)*m_x.getDimension(),10);
  const BigRealMatrix H       = createH();
  m_A                         = createHermiteReducingMatrix(H);
  BigRealMatrix       AHQ     = m_A * H; // N x (N-1)-matrix

  tcout << _T("Digits in calculation           :") << iparam(3) << m_digits  << endl
        << _T("Max number of digits in solution:") << iparam(3) << maxDigits << endl
        << _T("Max bound                       :") << dparam(5) << maxNorm   << endl;

  for(;;) {
    m_minBound = rQuot(BIGREAL_1, getMaxDiagElement(AHQ), 10);
    if(m_minBound > maxNorm) {
      return false; // we are out of digits
    }

    const int r = findPivotRow(AHQ); // Step 1: Exchange. r = [0..N-2]

    if(m_verbose&VERBOSE_PIVOT) {
      tcout << _T("Pivotrow:") << r << endl;
    }

    m_A.swapRows(r, r+1);
    AHQ.swapRows(r, r+1);

    if(r != m_n - 2) {   // Step 2: Corner
#ifdef TEST_ROTATION
      BigRealMatrix AHQTest = AHQ;
      AHQTest *= RotationMatrix1(AHQTest, r);
#endif // TEST_ROTATION
      AHQ *= RotationMatrix(AHQ, r);
    }

    // Step 3: Reduction
#ifdef TEST_REDUCEEXACT
    if(m_verbose&VERBOSE_MATRIX) {
      const BigRealMatrix D0    = createHermiteReducingMatrix0(AHQ);
      const BigRealMatrix D0AHQ = D0 * AHQ;
      tcout << _T("Hermite reducing Matrix D0:") << endl << dparam(8) << D0;
      tcout << _T("D0*AHQ:")                     << endl << dparam(8) << D0AHQ;
    }
#endif

    const BigRealMatrix D = createHermiteReducingMatrix(AHQ);
    if(m_verbose&VERBOSE_MATRIX) {
      tcout << _T("Hermite reducing Matrix D:") << endl << iparam(6) << D;
    }

    m_A = D * m_A;
    AHQ = D * AHQ;

    if(m_verbose&VERBOSE_MATRIX) {
      tcout << _T("AHQ:") << endl << dparam(8)  << AHQ;
      tcout << _T("A:"  ) << endl << iparam(16) << m_A;
    }

    // Step 4: check Termination
    try {
      const BigRealMatrix Ainv = round(inverse(m_A));
      const BigRealVector y    = m_x * Ainv;
      const int           z    = getZeroComponent(y);
      if(z >= 0) {
        if(m_verbose&VERBOSE_INVA) {
          tcout << _T("inv(A):") << endl << iparam(12) << Ainv;
        }
        if(m_verbose&VERBOSE_DATA) {
          tcout << _T("column:") << z << endl;
        }
        m_solution = Ainv.getColumn(z);
        return true;
      }
    } catch(Exception e) {
      return false; // Occurs when m_A is singular (Exception comes from inverse(m_A))
    }
  }
}