Esempio n. 1
0
int main(int argc, char ** argv)
{
	glutInit(&argc, argv);

	if (argc != 1 && argc != 6) {
		fprintf(stderr, "usage : %s N dt diff visc force source\n", argv[0]);
		fprintf(stderr, "where:\n"); \
			fprintf(stderr, "\t N      : grid resolution\n");
		fprintf(stderr, "\t dt     : time step\n");
		fprintf(stderr, "\t diff   : diffusion rate of the density\n");
		fprintf(stderr, "\t visc   : viscosity of the fluid\n");
		fprintf(stderr, "\t force  : scales the mouse movement that generate a force\n");
		fprintf(stderr, "\t source : amount of density that will be deposited\n");
		exit(1);
	}

	if (argc == 1) {
		N = 64;
		dt = 0.1f;
		diff = 0.0001f;
		visc = 0.0f;
		force = 5.0f;
		source = 100.0f;
		fprintf(stderr, "Using defaults : N=%d dt=%g diff=%g visc=%g force = %g source=%g\n",
			N, dt, diff, visc, force, source);
	}
	else {
		N = atoi(argv[1]);
		dt = atof(argv[2]);
		diff = atof(argv[3]);
		visc = atof(argv[4]);
		force = atof(argv[5]);
		source = atof(argv[6]);
	}

	printf("\n\nHow to use this demo:\n\n");
	printf("\t Add densities with the right mouse button\n");
	printf("\t Add velocities with the left mouse button and dragging the mouse\n");
	printf("\t Toggle density/velocity display with the 'v' key\n");
	printf("\t Toggle retro mode by pressing the 'p' key\n");
	printf("\t Clear the simulation by pressing the 'c' key\n");
	printf("\t Quit by pressing the 'q' key\n");

	dvel = false;
	pixel = false;
	
	solver.Init(N, dt, diff, visc);

	if (!solver.AllocateData()) exit(1);

	win_x = 512;
	win_y = 512;
	OpenGlutWindow();

	glutMainLoop();

	exit(0);
}
	bool simpleInitTest(ofstream& fout, Solver& solver, const Array& a,
			const Array& b, const Matrix& bin) {
		PrintABbin(fout, a, b, bin);
		fout << "-------------------------" << endl;
		solver.Init(a.size(), b.size(), bin);
		fout << "solver.Init(a.size(),b.size(),bin);" << endl;
		solver.PrintTestData(fout);
		fout << "-------------------------" << endl;
		return simpleNoPrintABbinTest(fout, solver, a.begin(), b.begin());
	}
Esempio n. 3
0
int main(int argc, char** argv)
{
	Solver *pSolver = new Solver();

	int nResultInit = pSolver->Init(argc, argv);
	switch( nResultInit ) {
		case EX_SUCCESS : {
			break;
		}
		case EX_FAILURE : {
			delete pSolver;
			return EX_SUCCESS;
			break;
		}
		default : {
			break;
		}
	}

	int nResultLoop = pSolver->Loop();
	switch( nResultLoop ) {
		case EX_SUCCESS : {
			break;
		}
		case EX_FAILURE : {
			delete pSolver;
			return EX_SUCCESS;
			break;
		}
		default : {
			break;
		}
	}

	int nResultPost = pSolver->Post();
	switch( nResultPost ) {
		case EX_SUCCESS : {
			break;
		}
		case EX_FAILURE : {
			delete pSolver;
			return EX_SUCCESS;
			break;
		}
		default : {
			break;
		}
	}

	delete pSolver;

  return EX_SUCCESS;
}
Esempio n. 4
0
int main(int argc, char* argv[]) {
  google::InitGoogleLogging(argv[0]);

  const int kNumberArguments = 6;
  if (argc < kNumberArguments) {
    LOG(ERROR) << "Usage: " << argv[0] << " "
               << "INSTANCE_FILE SOLVER RANDOM_SEED "
               << "ALGORITHM MAX_TIME [UPPER_BOUND] [SOLVER_LOG_LEVEL]";
    return argc;
  }

	string instance_file(argv[1]);
  string formulacao(argv[2]);
	int random_seed = atoi(argv[3]);
	string algorithm(argv[4]);
  int max_time = atoi(argv[5]);
  int upper_bound = (argc >= 7 ? atoi(argv[6]) : 0);
  if (argc >= 8)
    Globals::SetSolverLog(atoi(argv[7]));

  if (instance_file.find(".mps") != string::npos) {
    ReadAndSolveMpsFile(instance_file);
    return 0;
  }

  Globals::rg()->RandomInit(random_seed);
  VLOG(1) << "Loading instance file: " << instance_file;
  ProblemDataLoader loader(instance_file.c_str(), upper_bound, Globals::instance());
  loader.load();

  // Solver options
  SolverOptions options;
  options.set_max_time(max_time);
  options.set_relative_time_for_first_solution(Globals::instance()->n() *
                                               Globals::instance()->m());
  if (upper_bound > 0)
    options.set_cut_off_value(upper_bound);
  options.set_use_stabilization(true);

	// Solver and input options
  Solver* solver;
  SolverFactory* solver_factory;
  if (formulacao == "GeracaoColunas") {
    solver = new SolverGeracaoColunas(Globals::instance());
    solver_factory = new SolverGeracaoColunasFactory();
  } else if (formulacao == "FormulacaoPadrao") {
    solver = new SolverFormulacaoPadrao(Globals::instance());
    solver_factory = new SolverFormulacaoPadraoFactory();
  } else {
    LOG(FATAL) << "Inexistent formulation specified: " << formulacao;
    return 2;
  }

  // to keep the time
  Stopwatch^ sw = gcnew Stopwatch();

	// input options and final status
	SolverStatus status;
  //PopulateStatus status;

	if (algorithm == "CPLEX") {
		sw->Start();
		solver->Init(options);
    //solver->Populate(options, &status);
		solver->Solve(options, &status);
		sw->Stop();
	} else if (algorithm == "CPLEX-UB") {
    options.set_cut_off_value(upper_bound);
		sw->Start();
		solver->Init(options);
		solver->Solve(options, &status);
		sw->Stop();
	} else if (algorithm == "VNSBra") {
    //options.set_time_for_first_solution(60);
		sw->Start();
    LocalSearch::VNSBra(solver_factory, options.max_time() * 1000,
                        300 * 1000, 5, &status);
		sw->Stop();
	} else if (algorithm == "Memetic") {
		sw->Start();
		LocalSearch::MIPMemetic(&status);
		sw->Stop();
  } else if (algorithm == "PathRelink") {
    sw->Start();
    LocalSearch::PathRelink(solver_factory, options.max_time() * 1000,
                            120 * 1000, 1, &status);
    sw->Stop();
  } else if (algorithm == "PostProcessing") {
    sw->Start();
    LocalSearch::PostProcessing(solver_factory, options.max_time() * 1000,
                                120 * 1000, 1, &status);
    sw->Stop();
  } else {
    LOG(FATAL) << "Inexistent algorithm specified: " << algorithm;
    return 3;
  }

  status.time = sw->ElapsedMilliseconds / 1000.0;
	LOG(INFO) << status.ToString();
	return 0;
}
		bool initTest(Solver& solver, const Array& a,
				const Array& b, const Matrix& bin, double answer, double precision=1e-10) {
			solver.Init(a.size(), b.size(), bin);
			return solveTest(solver,a,b,answer,precision);
		}