Exemplo n.º 1
0
int main(int argc, char **argv)
{
    // Run all three problems
    for (unsigned int n = 0; n < 3; n++)
    {
        // initialize the planner
        og::SimpleSetupPtr ss = setupProblem(PlannerType(n));

        // attempt to solve the problem
        ob::PlannerStatus solved = ss->solve(10.0);

        if (solved)
        {
            if (solved == ob::PlannerStatus::EXACT_SOLUTION)
                std::cout << "Found solution.\n";
            else
                std::cout << "Found approximate solution.\n";

            // Set up to write the path
            std::ofstream f(problemName(PlannerType(n)).c_str());
            ompl::geometric::PathGeometric p = ss->getSolutionPath();
            p.interpolate();
            auto upstream(std::make_shared<ob::VFUpstreamCriterionOptimizationObjective>(
                ss->getSpaceInformation(), field));
            p.printAsMatrix(f);
            std::cout << "Total upstream cost: " << p.cost(upstream) << "\n";
        }
        else
            std::cout << "No solution found.\n";
    }

    return 0;
}
Exemplo n.º 2
0
DllExport int STDCALL C__hisCallSolver(void* Cptr)
{
   int rc = 1;
   char buffer[1024];
   gamshighs_t* gh;
   HighsStatus status;

   gh = (gamshighs_t*)Cptr;
   assert(gh->gmo != NULL);
   assert(gh->gev != NULL);

   gevLogStatPChar(gh->gev, "HiGHS " XQUOTE(HIGHS_VERSION_MAJOR) "." XQUOTE(HIGHS_VERSION_MINOR) "." XQUOTE(HIGHS_VERSION_PATCH) " [date: " HIGHS_COMPILATION_DATE ", git hash: " HIGHS_GITHASH "]\n");
   gevLogStatPChar(gh->gev, "Copyright (c) 2019 ERGO-Code under MIT licence terms.\n");

   gmoModelStatSet(gh->gmo, gmoModelStat_NoSolutionReturned);
   gmoSolveStatSet(gh->gmo, gmoSolveStat_SystemErr);

   /* get the problem into a normal form */
   gmoObjStyleSet(gh->gmo, gmoObjType_Fun);
   gmoObjReformSet(gh->gmo, 1);
   gmoIndexBaseSet(gh->gmo, 0);
   gmoSetNRowPerm(gh->gmo); /* hide =N= rows */
   gmoMinfSet(gh->gmo, -HIGHS_CONST_INF);
   gmoPinfSet(gh->gmo,  HIGHS_CONST_INF);

   if( setupOptions(gh) )
      goto TERMINATE;

   if( setupProblem(gh) )
      goto TERMINATE;

   gevTimeSetStart(gh->gev);

   /* solve the problem */
   status = gh->highs->run();

   /* pass solution, status, etc back to GMO */
   if( processSolve(gh, status) )
      goto TERMINATE;

   rc = 0;
TERMINATE:

   delete gh->lp;
   gh->lp = NULL;

   delete gh->highs;
   gh->highs= NULL;

   delete gh->options;
   gh->options = NULL;

   return rc;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
	//Initialize MPI
	MPI_Init(NULL, NULL);

	int whoAmI;
	MPI_Comm_rank(MPI_COMM_WORLD, &whoAmI);

    // Set up problem
    printf("Setting up problem...\n");
	fflush(stdout);
    double *A = (double*)malloc(sizeof(double)*(M*N)*(M*N));
    double *b = (double*)malloc(sizeof(double)*(M*N));
    double *x = (double*)malloc(sizeof(double)*(M*N));
    
    setupProblem(A, b, M, N);
    memset(x, (char)0, sizeof(double)*M*N);
    
	if (0 == whoAmI)
	{
		printf("ok\n");
		fflush(stdout);
	}

    // [Debug] Uncomment next line of code for printing a matrix/vector to a file.
    // Attention: Only do this for small matrices (i.e. M,N <= 8)!
    //printMatrixToFile("A.dat", A, M, N);
    
	if(0 == whoAmI)
	{
		printf("Solving...\n");
		fflush(stdout);
		//resetTime();
	}
    unsigned int iteration;
    for (iteration = 0; iteration < MAX_ITERATIONS; )
    {
		//visualize first, to see initial solution:
		if(0 == whoAmI)
		{
			printf("iterations: %d\n", iteration);
			fflush(stdout);
        
			// visualize
			unsigned char *pixels;
			visualizeMap(x, &pixels, M*N);
        
			// save bitmap
			printf("Saving bitmap...");
			fflush(stdout);
			char filename[64];
			sprintf(filename, "images/heatmap%d.bmp", iteration);
			if (!saveBMP(filename, pixels, M, N, 0))
			{
				printf("fail!\n");
				fflush(stdout);
				return 1;
			}
			else
			{
				printf("ok\n");
				fflush(stdout);
			}
			free(pixels);
		}
		
        // solve
        unsigned int iterationsDone = jacobi_solve(A, b, x, M*N, 10, 0.001);
        if (iterationsDone < 10) break;
        else iteration += iterationsDone;
    }
	if(0 == whoAmI)
	{
		//double timeNeededForSolving = getTime();
		//printf("End of computation!\nTime needed for solving: %fs\n", timeNeededForSolving);
	}
    
    free(A);
    free(b);
    free(x);

	MPI_Finalize();
   
    return 0;
}