Пример #1
0
int main(int argc, char **argv)
{

  str_param[0] = "";
  getCommandLine(int_ident, int_param, nia,
		 str_ident, str_param, nsa,
		 &(argv[1]), argc-1);
  
  if( argc < 2 || int_param[0] != NOVAL || !strcmp( argv[argc-1], "-h" ) )
    {
      outputHelpMessage();
    }
  else
    {
      SatSolver solver;

      solver.params.verbosity      = ( int_param[1] != NOVAL ? int_param[1] : 4 );
      solver.params.time_limit     = ( (double)(int_param[2] != NOVAL ? int_param[2] : -1 ) );
      solver.params.seed           = ( int_param[3] != NOVAL ? int_param[3] : 11041979 );	  
      solver.params.randomization  = ( int_param[4] != NOVAL ? abs(int_param[4]) : 2 );
      if(solver.params.randomization == 0)
	solver.params.randomization = 1;
      solver.params.shuffle        = ( int_param[4] > 0 );
      solver.params.restart_base   = ( int_param[5] != NOVAL ? int_param[5] : 200 );
      solver.params.restart_limit  = ( int_param[5] != NOVAL ? int_param[5] : 200 );
      solver.params.restart_factor = ( strcmp(str_param[0],"nil") ? atof(str_param[0]) : 1.05 );
      solver.params.decay          = ( strcmp(str_param[1],"nil") ? atof(str_param[1]) : .96 );
      solver.params.forgetfulness  = ( strcmp(str_param[2],"nil") ? atof(str_param[2]) : .75 );
      solver.setPolicy             ( ( strcmp(str_param[3],"luby") ? GEOMETRIC : LUBY ) );


      solver.parseDimacs(argv[1]);

      solver.printAll(std::cout);

      solver.solve();
    }
  return 0;
}
Пример #2
0
int main(int argc, char** argv)
{
    Options options;
    if (!parseCommandLine(argc, argv, options))
    {
        return 1;
    }
    
    std::cout << "-- Reading pattern from file: " << options.pattern << std::endl;
    Pattern pat;
    std::ifstream f(options.pattern);
    if (!f)
    {
        std::cout << "-- Error: Cannot open " << options.pattern << std::endl;
        return 1;
    }
    try
    {
        pat.load(f);
    }
    catch (std::exception& e)
    {
        std::cout << "-- Error: " << e.what() << std::endl;
        return 1;
    }

    SatSolver s;

    std::cout << "-- Building formula for " << options.evolutions << " evolution steps..." << std::endl;
    std::vector<Field> fields;
    for (int g = 0; g <= options.evolutions; ++g)
    {
        fields.push_back(Field(s, pat.width(), pat.height()));
        if (g > 0)
        {
            transition(s, fields[g-1], fields[g]);
        }
    }
    
    if (options.backwards)
    {
        std::cout << "-- Setting pattern constraint on last generation..." << std::endl;
        patternConstraint(s, fields.back(), pat);
    }
    else
    {
        std::cout << "-- Setting pattern constraint on first generation..." << std::endl;
        patternConstraint(s, fields.front(), pat);
    }

    std::cout << "-- Solving formula..." << std::endl;
    if (!s.solve())
    {
        std::cout << "-- Formula is not solvable. The selected pattern is probably too restrictive!" << std::endl;
        return 1;
    }

    std::cout << std::endl;
    for (int g = 0; g <= options.evolutions; ++g)
    {
        if (options.backwards)
        {
            if (g == 0)
            {
                std::cout << "-- Initial generation:" << std::endl;
            }
            else if (g == options.evolutions)
            {
                std::cout << "-- Evolves to final generation (from pattern):" << std::endl;
            }
            else
            {
                std::cout << "-- Evolves to:" << std::endl;
            }
        }
        else
        {
            if (g == 0)
            {
                std::cout << "-- Initial generation (from pattern):" << std::endl;
            }
            else if (g == options.evolutions)
            {
                std::cout << "-- Evolves to final generation:" << std::endl;
            }
            else
            {
                std::cout << "-- Evolves to:" << std::endl;
            }
        }
        fields[g].print(std::cout, s);
        std::cout << std::endl;
    }

    return 0;
}