本文整理汇总了C++中Solver::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Solver::add方法的具体用法?C++ Solver::add怎么用?C++ Solver::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solver
的用法示例。
在下文中一共展示了Solver::add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find
int find(int n, vector <int> rows, vector <int> columns, vector <int> values) {
m = rows.size();
if (m < n) {
return pow(10, (n - 1) * (n - 1) - m + 1);
}
// n <= 10
if (n == 1) {
return m == 0 ? 10 : 1;
}
memset(numbers, -1, sizeof(numbers));
for (int i = 0; i < m; ++ i) {
numbers[rows[i]][columns[i]] = values[i];
}
int answer = 1;
int mods[2] = {2, 5};
#define get_id(i, j) ((i) * n + (j))
for (int k = 0; k < 2; ++ k) {
int mod = mods[k];
Solver *solver = new Solver(mod);
int vars = 1;
for (int i = 0; i < n; ++ i) {
vector <int> row(n * n + 2);
for (int j = 0; j < n; ++ j) {
if (numbers[i][j] == -1) {
vars ++;
row[get_id(i, j)] = 1;
} else {
(row[n * n + 1] += numbers[i][j]) %= mod;
}
}
row[n * n] = 1;
solver->add(row);
}
for (int j = 0; j < n; ++ j) {
vector <int> row(n * n + 2);
for (int i = 0; i < n; ++ i) {
if (numbers[i][j] == -1) {
row[get_id(i, j)] = 1;
} else {
(row[n * n + 1] += numbers[i][j]) %= mod;
}
}
row[n * n] = 1;
solver->add(row);
}
int ret = solver->rank();
if (ret == -1) {
return 0;
}
answer = (long long)answer * pow(mod, vars - ret) % MOD;
}
#undef get_id
return answer;
}
示例2: make_tuple
template<class F> std::tuple<double,double> solve(double y, double x, std::vector<double> obs)
{
Solver<F> solver;
for(double o : obs)
solver.add(F(o),&x,&y);
solver.solve(DENSE,minimal_verbose());
return std::make_tuple(x,y);
}
示例3: toImplication
bool ClauseHead::toImplication(Solver& s) {
ConstraintType t = ClauseHead::type();
uint32 sz = isSentinel(head_[1]) ? 1 : 2 + (!s.isFalse(head_[2]) || s.level(head_[2].var()) > 0);
ClauseRep rep = ClauseRep::create(head_, sz, ClauseInfo(t).setLbd(2).setTagged(tagged()));
bool implicit = s.allowImplicit(rep);
bool locked = ClauseHead::locked(s) && s.decisionLevel() > 0;
rep.prep = 1;
if ((locked || !implicit) && sz > 1) { return false; }
s.add(rep, false);
detach(s);
return true;
}
示例4: addHeuristic
void addHeuristic( Solver& s, string Heu, const int rdz ) {
if(ValueO == "lex") {
for(int i=0; i<s.length; ++i)
s.sequence[i]->branch = new ValSelectorMin( s.sequence[i] );
} else if(ValueO == "rand") {
for(int i=0; i<s.length; ++i)
s.sequence[i]->branch = new ValSelectorRand( s.sequence[i] );
} else if(ValueO == "antilex") {
for(int i=0; i<s.length; ++i)
s.sequence[i]->branch = new ValSelectorMax( s.sequence[i] );
}
if( Heu == "dom" ) {
MinDomain h(abs(rdz));
s.add( h );
}
if( Heu == "lex" ) {
Lexicographic h;
s.add( h );
}
else if( Heu == "deg") {
MaxDegree h(abs(rdz));
s.add( h );
}
else if( Heu == "rand") {
Random h;
s.add( h );
}
else if( Heu == "dom+deg") {
MinDomMaxDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "domodeg") {
DomOverDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "domowldeg") {
DomOverWLDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "domowdeg") {
DomOverWDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "neighbor") {
Neighbor h(abs(rdz));
s.add( h );
}
else if( Heu == "impact") {
Impact h(abs(rdz));
s.add( h );
}
else if( Heu == "impactodeg") {
ImpactOverDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "impactowdeg") {
ImpactOverWDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "impactowldeg") {
ImpactOverWLDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "fpp") {
FPP h(abs(rdz));
s.add( h );
}
else {
NoOrder h;
s.add( h );
}
}
示例5: main
int main(int argc, char *argv[])
{
// double time, start = get_run_time();
// for(int i=0; i<10000000; ++i) {
// time = get_run_time();
// }
// std::cout << (get_run_time() - start) << std::endl;
// // double time, start = cpu_time();
// // for(int i=0; i<10000000; ++i) {
// // time = cpu_time();
// // }
// // std::cout << (cpu_time() - start) << std::endl;
// exit(1);
int i, j, N=8;
if(argc>1) N = atoi(argv[1]);
VarArray X(N, 1, N);
Vector< VarArray > differences;
Solver s;
s.add( AllDiff(X) );
VarArray scope;
for(i=1; i<N-1; ++i) {
scope.clear();
for(j=0; j<N-i; ++j) {
scope.add(X[j]-X[j+i]);
}
s.add( AllDiff(scope, FORWARD_CHECKING) );
differences.add(scope);
}
cout << s << endl;
s.rewrite();
cout << s << endl;
s.consolidate();
cout << s << endl;
s.parameters.verbosity = 2;
if(s.depth_first_search(X,
new GenericHeuristic<
// GenericNeighborDVO<
// FailureCountManager,
// //PruningCountManager,
// SelfPlusAverage,
// MinDomainOverWeight
// //MinNeighborDomainOverNeighborWeight
// , 1
GenericDVO<
MinDomainOverWeight, 1,
FailureCountManager
>,
MinValue >(&s),
new Geometric()) == SAT) {
for(i=0; i<N; ++i)
cout << setw(3) << X[i].get_solution_int_value() << " " ;
cout << endl;
for(i=0; i<N-2; ++i) {
for(j=0; j<N-i-1; ++j)
cout << setw(3) << differences[i][j].get_solution_int_value() << " " ;
cout << endl;
}
cout << setw(3) << (X[0].get_solution_int_value() - X[N-1].get_solution_int_value()) << endl << endl;
}
//std::cout << s.statistics << std::endl;
}
示例6: main
int main(int argc, char *argv[])
{
#ifdef _FLATZINC_OUTPUT
cout << "%";
#endif
SolverCmdLine cmd("Mistral (fzn)", ' ', "2.0");
TCLAP::SwitchArg annotationArg("","follow_annotations","Uses the annotations", false);
cmd.add( annotationArg );
TCLAP::ValueArg<int> parityArg("","parity","Uses parity processing", false, 0, "int");
cmd.add( parityArg );
TCLAP::SwitchArg simple_rewriteArg("","simple_rewrite","Uses simple rewriting", false);
cmd.add( simple_rewriteArg );
#ifdef _PARALLEL
//std::cout << "PARALLEL \n \n \n " << std::endl;
TCLAP::ValueArg<int> threadsArg("p","number-threads","Use multithreading with this option.", false, 4, "int");
cmd.add( threadsArg );
#endif
cmd.parse(argc, argv);
#ifdef _PARALLEL
int total = threadsArg.getValue();
if (cmd.enumerate_solutions())
total=1;
else{
//std::cout << "Available threads : " << omp_get_max_threads() << std::endl;
//int recommended= floor((double) (omp_get_max_threads()*3) / 4.0 ) ;
int recommended= floor((double) (omp_get_max_threads()) / 2.0 ) ;
if (total >recommended){
//std::cout << " % " << " high value of -p. The solver will use only " << recommended << " threads (recommended) " << std::endl;
total=recommended;
}
}
// else
// std::cout << " % " << " will use " << total << " threads " << std::endl;
omp_set_num_threads(total);
long int global_obj =std::numeric_limits<int>::max();
bool solution_found_elsewhere= false;
#endif
#ifdef _PARALLEL
#pragma omp parallel
{
//printf("multicore user! %d \n" , omp_get_thread_num());
int id = omp_get_thread_num();
#endif
int thread_seed = cmd.get_seed();
#ifdef _PARALLEL
thread_seed+=id;
#endif
usrand(thread_seed);
Solver s;
cmd.set_parameters(s);
std::string policy;
#ifdef _PARALLEL
if ( id%2 != 0)
if (cmd.get_restart_policy()=="geom")
policy="luby";
else
policy="geom";
else
#endif
policy =cmd.get_restart_policy();
#ifdef _PARALLEL
bool branch_on_auxilary = true;
if ( id%4 < 2 )
branch_on_auxilary=false;
//#pragma omp critical
// std::cout << " " << s.parameters.prefix_statistics << "ID: " << id << " " << policy << " branch_on_auxilary " << branch_on_auxilary << " "<< thread_seed << std::endl;
#endif
double cpu_time = get_run_time() ;
#ifdef _VERBOSE_PARSER
std::cout << " " << s.parameters.prefix_comment << " Parse: ";
#endif
FlatZinc::Printer p;
FlatZinc::FlatZincModel *fm = 0L;
fm = parse(cmd.get_filename(), s, p);
if( !fm )
//.........这里部分代码省略.........
示例7: addHeuristic
void addHeuristic( Solver& s ) {
if( Heu == "dom" ) {
MinDomain h(abs(rdz));
s.add( h );
}
if( Heu == "lex" ) {
Lexicographic h;
s.add( h );
}
else if( Heu == "deg") {
MaxDegree h(abs(rdz));
s.add( h );
}
else if( Heu == "rand") {
Random h;
s.add( h );
}
else if( Heu == "dom+deg") {
MinDomMaxDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "dom/deg") {
DomOverDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "dom/wldeg") {
DomOverWLDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "dom/wdeg") {
DomOverWDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "neighbor") {
Neighbor h(abs(rdz));
s.add( h );
}
else if( Heu == "impact") {
Impact h(abs(rdz));
s.add( h );
}
else if( Heu == "impact/deg") {
ImpactOverDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "impact/wdeg") {
ImpactOverWDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "impact/wldeg") {
ImpactOverWLDeg h(abs(rdz));
s.add( h );
}
else {
NoOrder h;
s.add( h );
}
if(ValHeu == "anti") {
s.setAntiLex();
} else if(ValHeu == "rand") {
s.setRandMinMax();
} else if(ValHeu == "split") {
s.setSplit();
} else if(ValHeu == "rsplit") {
s.setRandSplit();
} else if(ValHeu != "lex") {
std::cerr << "Warning: unknown value selection heuristic" << std::endl;
}
}
示例8: addHeuristic
void addHeuristic( Solver& s ) {
if( Heu == "dom" ) {
MinDomain h(abs(rdz));
s.add( h );
}
if( Heu == "lex" ) {
Lexicographic h;
s.add( h );
}
else if( Heu == "deg") {
MaxDegree h(abs(rdz));
s.add( h );
}
else if( Heu == "rand") {
Random h;
s.add( h );
}
else if( Heu == "dom+deg") {
MinDomMaxDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "dom/deg") {
DomOverDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "dom/wldeg") {
DomOverWLDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "dom/wdeg") {
DomOverWDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "neighbor") {
Neighbor h(abs(rdz));
s.add( h );
}
else if( Heu == "impact") {
Impact h(abs(rdz));
s.add( h );
}
else if( Heu == "impact/deg") {
ImpactOverDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "impact/wdeg") {
ImpactOverWDeg h(abs(rdz));
s.add( h );
}
else if( Heu == "impact/wldeg") {
ImpactOverWLDeg h(abs(rdz));
s.add( h );
}
else {
NoOrder h;
s.add( h );
}
}