示例#1
0
文件: csfz.cs 项目: njb0401/JobShop
    /**
     * Loads a flatzinc file (passed as the first argument) and solves it.
     */
    private static void Solve(String filename)
    {
        FzModel model = new FzModel(filename);

        model.LoadFromFile(filename);
        // Uncomment to see the model.
        // Console.WriteLine(model.ToString());
        // This is mandatory.
        model.PresolveForCp();
        // Display basic statistics on the model.
        model.PrintStatistics();

        FzSolverParameters parameters = new FzSolverParameters();

        // Initialize to default values as in the C++ runner.
        parameters.all_solutions    = false;
        parameters.free_search      = false;
        parameters.last_conflict    = false;
        parameters.heuristic_period = 100;
        parameters.ignore_unknown   = false;
        parameters.log_period       = 10000000;
        parameters.luby_restart     = -1;
        parameters.num_solutions    = 0;
        parameters.restart_log_size = -1;
        parameters.threads          = 0;
        parameters.time_limit_in_ms = 10000;
        parameters.use_log          = true;
        parameters.verbose_impact   = false;
        parameters.worker_id        = -1;
        parameters.search_type      = FzSolverParameters.DEFAULT;
        // Mandatory to retrieve solutions.
        parameters.store_all_solutions = true;

        FzSolver solver = new FzSolver(model);

        solver.SequentialSolve(parameters);

        int last = solver.NumStoredSolutions() - 1;

        if (last >= 0)
        {
            FzOnSolutionOutputVector output_vector = model.output();
            foreach (FzOnSolutionOutput output in output_vector)
            {
                if (output.variable != null)
                {
                    FzIntegerVariable var = output.variable;
                    Console.WriteLine(var.name + " = " + solver.StoredValue(last, var));
                }
                foreach (FzIntegerVariable var in output.flat_variables)
                {
                    Console.WriteLine(var.name + " = " + solver.StoredValue(last, var));
                }
            }
        }
    }
示例#2
0
  /**
   * Loads a flatzinc file (passed as the first argument) and solves it.
   */
  private static void Solve(String filename)
  {
    FzModel model = new FzModel(filename);
    model.LoadFromFile(filename);
    // Uncomment to see the model.
    // Console.WriteLine(model.ToString());
    // This is mandatory.
    model.PresolveForCp();
    // Display basic statistics on the model.
    model.PrintStatistics();

    FzSolverParameters parameters = new FzSolverParameters();
    // Initialize to default values as in the C++ runner.
    parameters.all_solutions = false;
    parameters.free_search = false;
    parameters.last_conflict = false;
    parameters.heuristic_period = 100;
    parameters.ignore_unknown = false;
    parameters.log_period = 10000000;
    parameters.luby_restart = -1;
    parameters.num_solutions = 0;
    parameters.restart_log_size = -1;
    parameters.threads = 0;
    parameters.time_limit_in_ms = 10000;
    parameters.use_log = true;
    parameters.verbose_impact = false;
    parameters.worker_id = -1;
    parameters.search_type = FzSolverParameters.DEFAULT;
    // Mandatory to retrieve solutions.
    parameters.store_all_solutions = true;

    FzSolver solver = new FzSolver(model);
    solver.SequentialSolve(parameters);

    int last = solver.NumStoredSolutions() - 1;
    if (last >= 0) {
      FzOnSolutionOutputVector output_vector = model.output();
      foreach (FzOnSolutionOutput output in output_vector) {
        if (output.variable != null) {
          FzIntegerVariable var = output.variable;
          Console.WriteLine(var.name +  " = " + solver.StoredValue(last, var));
        }
        foreach (FzIntegerVariable var in output.flat_variables) {
          Console.WriteLine(var.name +  " = " + solver.StoredValue(last, var));
        }
      }
    }
  }