Ejemplo n.º 1
0
std::string SumOfDivided::sumOfDivided(std::vector<int> &lst){
    if (lst.size() == 0){
        return "";
    } else {
        return computeSolution(lst);
    }
};
Ejemplo n.º 2
0
 void LinearSystem::solve( void )
 // solves the system and automatically stores the result in the variables
 // for an overdetermined system, computes a least-squares solution
 {
    convertEquations();
    indexVariables();
    buildSparseMatrix();
    buildRightHandSide();
    computeSolution();
 }
Ejemplo n.º 3
0
void FaToDFA::setMode(Algorithm::modes _mode)
{
    mode = _mode;
    play_timer->stop();
    num = 0;
    actInstruction=HEADER;
    prewInstruction=HEADER;

    clearActInstruction();
    clearVariables();
    // because show correct solution break connectiom betwen user FA and user FA widget
    connect(dfa_widget,SIGNAL(FA_changed(FiniteAutomata*)),this,SLOT(setDFA(FiniteAutomata*)));

    switch (mode)
    {
        case PLAY_MODE:
            algorithm_widget->enableNext();
            algorithm_widget->disablePrev();
            dfa_widget->setFA(new FiniteAutomata());
            //unselect instruction from algorithm window
            clearActInstruction();
            history.clear();
            actPos = 0;
            actInstruction = HEADER; //init start instruction because new regExp may appeare when pres step mode was in run
            saveStep();
        break;
        case CHECK_MODE: case STEP_MODE:
            correct_FA = computeSolution();
        break;
        case NONE:
        break;
    }

    if(mode == STEP_MODE)
        check_step_timer->start(CHECK_STEP_TIMEOUT);
    else
        check_step_timer->stop();

    dfa_widget->clearStatus();
}
Ejemplo n.º 4
0
int main()
{
	init_vector.push_back(10);
	init_vector.push_back(231);
	init_vector.push_back(13);
	init_vector.push_back(14);
	init_vector.push_back(57);
	init_vector.push_back(127);
	init_vector.push_back(32);
	
	std::sort(init_vector.begin(), init_vector.end());
	
	splitInitVector();

	printVector("first half", first_half);
	printVector("second_half", second_half);



	computeSums(first_half, first_sums);
	std::sort(first_sums.begin(), first_sums.end());
	printVector("first_sums", first_sums);
	std::cout<<"#################################\n";
	computeSums(second_half, second_sums);
	std::sort(second_sums.begin(), second_sums.end());
	printVector("second_sums", second_sums);
	std::cout<<"#################################\n";


	computeSolution();
	
	
	printVector("solution", solution);

	return 0;
}
Ejemplo n.º 5
0
  void HCOD::activeSearch( VectorXd & u )
  {
    // if( isDebugOnce ) {  sotDebugTrace::openFile();  isDebugOnce = false; }
    // else { if(sotDEBUGFLOW.outputbuffer.good()) sotDebugTrace::closeFile(); }
    //if(sotDEBUGFLOW.outputbuffer.good()) { sotDebugTrace::closeFile();sotDebugTrace::openFile(); }
    sotDEBUGIN(15);
    /*
     * foreach stage: stage.initCOD(Ir_init)
     * u = 0
     * u0 = solve
     * do
     *   tau,cst_ref = max( violation(stages) )
     *   u += (1-tau)u0 + tau*u1
     *   if( tau<1 )
     *     update(cst_ref); break;
     *
     *   lambda,w = computeLambda
     *   cst_ref,lmin = min( lambda,w )
     *   if lmin<0
     *     downdate( cst_ref )
     *
     */

    assert(VectorXi::LinSpaced(3,0,2)[0] == 0
	   && VectorXi::LinSpaced(3,0,2)[1] == 1
	   && VectorXi::LinSpaced(3,0,2)[2] == 2
	   && "new version of Eigen might have change the "
	   "order of arguments in LinSpaced, please correct");

    /*struct timeval t0,t1,t2;double time1,time2;
    gettimeofday(&t0,NULL);*/
    initialize();
    sotDEBUG(5) << "Y= " << (MATLAB)Y.matrixExplicit<< std::endl;
    Y.computeExplicitly(); // TODO: this should be done automatically on Y size.
    sotDEBUG(5) << "Y= " << (MATLAB)Y.matrixExplicit<< std::endl;
    /*gettimeofday(&t1,NULL);
    time1 = ((t1.tv_sec-t0.tv_sec)+(t1.tv_usec-t0.tv_usec)/1.0e6);*/

    int iter = 0;

	startTime=getCPUtime();
    Index stageMinimal = 0;
    do
      {
	iter ++; sotDEBUG(5) << " --- *** \t" << iter << "\t***.---" << std::endl;
	//if( iter>1 ) { break; }

	if( sotDEBUG_ENABLE(15) )  show( sotDEBUGFLOW );
	assert( testRecomposition(&std::cerr) );
	damp();
	computeSolution();
	assert( testSolution(&std::cerr) );

	double tau = computeStepAndUpdate();
	if( tau<1 )
	  {
	    sotDEBUG(5) << "Update done, make step <1." << std::endl;
	    makeStep(tau);
	  }
	else
	  {
	    sotDEBUG(5) << "No update, make step ==1." << std::endl;
	    makeStep();

	    for( ;stageMinimal<=(Index)stages.size();++stageMinimal )
	      {
		sotDEBUG(5) << "--- Started to examinate stage " << stageMinimal << std::endl;
		computeLagrangeMultipliers(stageMinimal);
		if( sotDEBUG_ENABLE(15) )  show( sotDEBUGFLOW );
		//assert( testLagrangeMultipliers(stageMinimal,std::cerr) );

		if( searchAndDowndate(stageMinimal) )
		  {
		    sotDEBUG(5) << "Lagrange<0, downdate done." << std::endl;
		    break;
		  }

		for( Index i=0;i<stageMinimal;++i )
		  stages[i]->freezeSlacks(false);
		if( stageMinimal<nbStages() )
		  stages[stageMinimal]->freezeSlacks(true);

	      }
	  }
	lastTime=getCPUtime()-startTime;
	lastNumberIterations=iter;

	if( lastTime>maxTime ) throw 667;
	if( iter>maxNumberIterations ) throw 666;
    } while(stageMinimal<=nbStages());
    sotDEBUG(5) << "Lagrange>=0, no downdate, active search completed." << std::endl;
    /*gettimeofday(&t2,NULL);
    time2 = ((t2.tv_sec-t1.tv_sec)+(t2.tv_usec-t1.tv_usec)/1.0e6);
    std::ofstream fup("/tmp/haset.dat",std::ios::app);
    fup << time1<<"\t"<<time2<<"\t"<<iter<<"\t";*/

    u=solution;
    sotDEBUG(5) << "uf =" << (MATLAB)u << std::endl;
    sotDEBUGOUT(15);
  }