Пример #1
0
int con_branching()
{
    CONSTRAINT *row0,*row1;
    double     old_lowerb = lowerb;


#ifdef STAMP
    std::cout << "  >>>>>>>>>>>>> constraint branching " << std::endl;
    if(branchs==0) write_sol(fsolution);
#endif

    if( upperb < ceil(lowerb-ZERO)+ZERO ) return(1);
////    constraint_branching(nbetter,better,&row0,&row1);
    constraint_branching(nsupport,support,&row0,&row1);
    if( upperb < ceil(lowerb-ZERO)+ZERO ) return(1);
    if(row0==NULL && row1==NULL)return(-1);
    if(row0==NULL || row1==NULL)return(0);


/***
 to do not use the branch-cuts
***/
////    return(-1);



    branchs++;
#ifdef STAMP
    std::cout << "branching " << branchs << " on constraint" << std::endl;
#endif


/* making the left child */

    row0->stat = LP_BA;
    add_rows(1,&row0);
    lowerb = solve_lp(0);
    get_solution();
    get_base();
    write_prob();
    deletelastrow();
    row0->stat = FIX_LB;

/* making the left child */


    row1->stat = LP_BA;
    add_rows(1,&row1);
    lowerb = solve_lp(0);
    get_solution();
    get_base();
    write_prob();
    deletelastrow();
    row1->stat = FIX_LB;

    lowerb = old_lowerb;
    return(1);
}
Пример #2
0
double     solve_child_row(CONSTRAINT *row,int sol)

{
    int    i,rmatbeg,cont;
    double lb,rhs;
    int    *rmatind;
    double *rmatval;
    char   sense;
    
    cont    = row->card;
    rhs     = row->rhs;
    sense   = row->sense;
    rmatbeg = 0;
    rmatind = (int *)malloc( cont * sizeof(int) );
    if( rmatind==NULL ){        
        std::cout << " ERROR: not enough memory for branch-constraint" << std::endl;
        CSPexit(EXIT_MEMO); //exit(1);
    }
    for(i=0;i<cont;i++) rmatind[i] = row->stack[i]->lp;
    rmatval = (double *)malloc( cont * sizeof(double) );
    if( rmatval==NULL ){        
        std::cout << " ERROR: not enough memory for branch-constraint" << std::endl;
        CSPexit(EXIT_MEMO); //exit(1);
    }
    for(i=0;i<cont;i++) rmatval[i] = 1.0;

    if (JJaddrows(lp,0,1,cont,&rhs,&sense,
        &rmatbeg,rmatind,rmatval,NULL,NULL) ) {        
        std::cout << " ERROR: it was not possible to add branch constraint" << std::endl;
        CSPexit(EXIT_LPSOLVER); //exit(1);
    }
    free( (void *)rmatval );
    rmatval = NULL; /*PWOF*/
    free( (void *)rmatind );
    rmatind = NULL; /*PWOF*/

    pricing_util = 0;
    lb = solve_lp(0);
    if( sol ) {
        get_solution();
        get_base();
    }
    integer_solution();

    if( JJdelrows(lp,mar,mar) ){        
        std::cout << " ERROR: it was not possible to delete branch constraint" << std::endl;
        CSPexit(EXIT_LPSOLVER); //exit(1);
    }
    return(lb);
}
Пример #3
0
bool 
AirspaceWarning::operator<(const AirspaceWarning &other) const
{
  // compare bother.ack
  if (get_ack_expired() != other.get_ack_expired())
    // least expired top
    return get_ack_expired() > other.get_ack_expired();

  // compare bother.state
  if (get_warning_state() != other.get_warning_state())
    // most severe top
    return get_warning_state() > other.get_warning_state();

  // state and ack equal, compare bother.time to intersect
  return get_solution().elapsed_time < other.get_solution().elapsed_time;
}
Пример #4
0
double     solve_child_col(VARIABLE   *col,double val,int sol)

{
    double lb;
    int    index[2];
    double value[2];
    char   lu[2];

    if(col->lp<0){        
        std::cout << "ERROR: variable not in the LP: stat=" << col->stat << std::endl;
        CSPexit(EXIT_ERROR); //exit(1);
    }

    index[0] = col->lp;
    lu[0]    = 'B';
    value[0] = val;
    if( JJchgbds(lp,1,index,lu,value) ){        
        std::cout << "ERROR: it is not possible to fix LP-var " << col->index << std::endl;
        CSPexit(EXIT_LPSOLVER); //exit(1);
    }

    pricing_util = 0;
    lb = solve_lp(0);
    if( sol ){
        get_solution();
        get_base();
    }
    integer_solution();

    index[1] = col->lp;
    lu[0]    = 'L';
    lu[1]    = 'U';
    value[0] = 0.0;
    value[1] = 1.0;
    if( JJchgbds(lp,2,index,lu,value) ){        
        std::cout << "ERROR: it is not possible to fix LP-var " << col->index << std::endl;
        CSPexit(EXIT_LPSOLVER); //exit(1);
    }
    return(lb);
}
Пример #5
0
void SMTSolver_eq::get_solution()
{
	assert((settings_s.smte_s && !settings_s.smtc_s) ||
	(!settings_s.smte_s && settings_s.smtc_s));
	OUTDEBUG(cerr << "[SMT]Computing solution." << endl);
	map<int,int> id_composante;
	int id = 0;

	if(settings_s.smte_s)
	{
		for(auto s : edge)
			if(id_composante.find(s.first) == id_composante.end())
			{
				visite_composante(s.first, id, id_composante);
				id++;
			}
	}
	else
	{
		for(auto s : solver->terms_mapping)
		{
			if(s.first != 0 && connectivity_check.find(s.first) == nullptr)
				connectivity_check.add(s.first);

			if(s.first != 0 && id_composante.find(s.first) == id_composante.end())
			{
				visite_composante_qf(connectivity_check.find(s.first), id, id_composante);
				id++;
			}
		}
	}


	for(auto s1 : not_possible)
		for(auto s2: s1.second)
		{
			if(id_composante.find(s1.first) == id_composante.end())
			{
				id_composante[s1.first] = id;
				id++;
			}
			if(id_composante.find(s2.first) == id_composante.end())
			{
				id_composante[s2.first] = id;
				id++;
			}
		}

	map<int,vector<int>> composante;
	for(auto a : id_composante)
		composante[a.second].push_back(a.first);

	for(auto c : composante)
	{
		OUTDEBUG(cerr << "C" << c.first << ", "<<  connectivity_check.find(c.second[0])->getValue() << ": {");
		unsigned int k = 0;
		for(auto b: c.second)
		{
			OUTDEBUG(cerr << b << ((k == c.second.size()-1) ? "" : ", "));
			k ++;
		}
		OUTDEBUG(cerr << "}" << endl);
	}

	OUTDEBUG(cerr << "Non equalities : " << endl);
	for(auto s1 : not_possible)
		for(auto s2: s1.second)
			OUTDEBUG(cerr << s1.first << " != " << s2.first << " " << connectivity_check.find(s1.first)->getValue() << " != " << connectivity_check.find(s2.first)->getValue() << endl);
	
	for(int i = 0 ; i < id ; i++)
	{
		for(int j = i+1 ; j < id ; j++)
		{
			OUTDEBUG(cerr << "Trying to merge C" << i << " and " << "C" << j << endl);
			int r1 = connectivity_check.find(composante[i][0])->getValue();
			int r2 = connectivity_check.find(composante[j][0])->getValue();
			bool possible = true;
			for(auto s1 : not_possible)
				for(auto s2: s1.second)
					if((((int)connectivity_check.find(s1.first)->getValue() == r1) && ((int)connectivity_check.find(s2.first)->getValue() == r2)) ||
				   		(((int)connectivity_check.find(s1.first)->getValue() == r2) && ((int)connectivity_check.find(s2.first)->getValue() == r1)))
				   		possible = false;
			if(possible)
			{
				OUTDEBUG(cerr << "\tRepresented by " << r1 << " and " << r2 << endl);
				OUTDEBUG(cerr << "\tMerging possible !" << endl);
				connectivity_check.make_union(r1, r2);
				edge[r1][r2] = -1;
				edge[r2][r1] = -1;	

				get_solution();
				return;
			}
		}
	}

	for(auto c : composante)
	{
		if(settings_s.smte_s)
			cout << "C(" << connectivity_check.find(c.second[0])->getValue() << "): {";
		else
			cout << "C(" << solver->terms_mapping[connectivity_check.find(c.second[0])->getValue()]->to_str() << "): {";
		unsigned int k = 0;
		for(auto b: c.second)
		{
			cout << ((settings_s.smte_s) ? to_string(b) : solver->terms_mapping[b]->to_str()) << ((k == c.second.size()-1) ? "" : ", ");
			k ++;
		}
		cout << "}" << endl;
	}

}
Пример #6
0
int read_prob()
{
    int            k,l,lcuts,cont;
    CONSTRAINT     **stack = NULL;
    long           offset;
    struct BRANCH  *ptr;
    VARIABLE       *col;
    FILE           *pfile;
//    float          t1;

    do{
        if( tree==NULL ) return(0);
        offset = tree->file;
        lowerb = tree->val;
        ptr    = tree->next;
        free(tree);
        tree   = ptr;
    }while( ceil(lowerb-ZERO)+ZERO > upperb );
#ifdef STAMP
    std::cout << "  >>>>>>>>>>>>> reading problem " << (float)lowerb << std::endl;
#endif
 //   t1 = seconds();
    pfile = fopen(fbranch,"r");
    if(pfile==NULL){          
          std::cout << "ERROR: not possible to write on " << fbranch << std::endl;
          CSPexit(EXIT_ERROR); //exit(1);
    }
    fseek(pfile,offset,SEEK_SET);

    for(k=0;k<ncols;k++)
         columns[k].stat = FIX_LB;
    fscanf(pfile,"%d",&cont);
    for(k=0;k<cont;k++){
         fscanf(pfile,"%p %d",&col,&l);
         col->stat = l;
    }
    fscanf(pfile,"%d",&lcuts);

    if(lcuts){
         stack = (CONSTRAINT **)malloc( lcuts * sizeof( CONSTRAINT *) );
         if( stack==NULL ){              
              std::cout << "ERROR: not enought memory for STACK" << std::endl;
              CSPexit(EXIT_MEMO); //exit(1);
         }
         for(k=0;k<lcuts;k++){
              fscanf(pfile,"%p",stack+k);
              stack[k]->stat = 0;
         }
    }
    fclose(pfile);

    load_lp();
    if(lcuts){
        add_rows(lcuts,stack);
        free( (void *)stack );
        stack = NULL; /*PWOF*/
    }
    put_base();
    setup_lp();
    get_solution();
    return(1);
}
Пример #7
0
int main(void)
{
    printf("Result %lld\n", get_solution());
    return 0;
}