当前位置: 首页>>代码示例>>C++>>正文


C++ Solver::add方法代码示例

本文整理汇总了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;
    }
开发者ID:3013216027,项目名称:acm-icpc,代码行数:54,代码来源:TheMagicMatrix.cpp

示例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);
}
开发者ID:Barbakas,项目名称:LMA,代码行数:8,代码来源:derivatives.cpp

示例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;
}
开发者ID:lc2casp,项目名称:lc2casp,代码行数:12,代码来源:solver_types.cpp

示例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 );
  }
}
开发者ID:AbdullahMohammad,项目名称:Numberjack,代码行数:74,代码来源:square_packing.cpp

示例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;
}
开发者ID:AbdullahMohammad,项目名称:Numberjack,代码行数:81,代码来源:costas_array.cpp

示例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 )
//.........这里部分代码省略.........
开发者ID:siala,项目名称:SM,代码行数:101,代码来源:main-fz.cpp

示例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;
  } 

}
开发者ID:AbdullahMohammad,项目名称:Numberjack,代码行数:71,代码来源:random_csp.cpp

示例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 );
  }
}
开发者ID:AbdullahMohammad,项目名称:Numberjack,代码行数:58,代码来源:kappa.cpp


注:本文中的Solver::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。