コード例 #1
0
ファイル: cpp_example.cpp プロジェクト: b45ch1/adol-c
int main(int argv, char* argc[])
{
  // Create an instance of your nlp...
  SmartPtr<TNLP> myadolc_nlp = new MyADOLC_sparseNLP();

  // Create an instance of the IpoptApplication
  SmartPtr<IpoptApplication> app = new IpoptApplication();

  // Initialize the IpoptApplication and process the options
  ApplicationReturnStatus status;
  status = app->Initialize();
  if (status != Solve_Succeeded) {
    printf("\n\n*** Error during initialization!\n");
    return (int) status;
  }

  status = app->OptimizeTNLP(myadolc_nlp);

  if (status == Solve_Succeeded) {
    // Retrieve some statistics about the solve
    Index iter_count = app->Statistics()->IterationCount();
    printf("\n\n*** The problem solved in %d iterations!\n", iter_count);

    Number final_obj = app->Statistics()->FinalObjective();
    printf("\n\n*** The final value of the objective function is %e.\n", final_obj);
  }

  return (int) status;
}
コード例 #2
0
ファイル: cpp_example.cpp プロジェクト: venuur/dissertation
int main(int argv, char* argc[])
{
  // Create an instance of your nlp...
  SmartPtr<TNLP> mynlp = new MyNLP(0.00024682, 0.0015247, 0.0);

  // Create an instance of the IpoptApplication
  //
  // We are using the factory, since this allows us to compile this
  // example with an Ipopt Windows DLL
  SmartPtr<IpoptApplication> app = IpoptApplicationFactory();

  // Initialize the IpoptApplication and process the options
  ApplicationReturnStatus status;
  status = app->Initialize();
  if (status != Solve_Succeeded) {
    std::cout << std::endl << std::endl << "*** Error during initialization!" << std::endl;
    return (int) status;
  }

  status = app->OptimizeTNLP(mynlp);

  if (status == Solve_Succeeded) {
    // Retrieve some statistics about the solve
    Index iter_count = app->Statistics()->IterationCount();
    std::cout << std::endl << std::endl << "*** The problem solved in " << iter_count << " iterations!" << std::endl;

    Number final_obj = app->Statistics()->FinalObjective();
    std::cout << std::endl << std::endl << "*** The final value of the objective function is " << final_obj << '.' << std::endl;
  }

  return (int) status;
}
コード例 #3
0
int main(
   int argv,
   char* argc[]
   )
{
   // Set the data:

   // Number of variables
   Index N = 100;

   // constant terms in the constraints
   Number* a = new double[N - 2];
   for( Index i = 0; i < N - 2; i++ )
   {
      a[i] = (double(i + 2)) / (double) N;
   }

   // Create a new instance of your nlp
   //  (use a SmartPtr, not raw)
   SmartPtr<TNLP> mynlp = new TutorialCpp_NLP(N, a);

   // Create a new instance of IpoptApplication
   //  (use a SmartPtr, not raw)
   SmartPtr<IpoptApplication> app = new IpoptApplication();

   // Change some options
   // Note: The following choices are only examples, they might not be
   //       suitable for your optimization problem.
   app->Options()->SetNumericValue("tol", 1e-10);
   app->Options()->SetStringValue("mu_strategy", "adaptive");

   // Intialize the IpoptApplication and process the options
   app->Initialize();

   // Ask Ipopt to solve the problem
   ApplicationReturnStatus status = app->OptimizeTNLP(mynlp);

   if( status == Solve_Succeeded )
   {
      printf("\n\n*** The problem solved!\n");
   }
   else
   {
      printf("\n\n*** The problem FAILED!\n");
   }

   // As the SmartPtrs go out of scope, the reference count
   // will be decremented and the objects will automatically
   // be deleted.

   // However, we created the Number array for a here and have to delete it
   delete[] a;

   return (int) status;
}
コード例 #4
0
ファイル: hs071_main.cpp プロジェクト: MengbinZhu/pfldp
int main(int argv, char* argc[])
{
  // Create a new instance of your nlp
  //  (use a SmartPtr, not raw)
  SmartPtr<TNLP> mynlp = new HS071_NLP();

  // Create a new instance of IpoptApplication
  //  (use a SmartPtr, not raw)
  // We are using the factory, since this allows us to compile this
  // example with an Ipopt Windows DLL
  SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
  app->RethrowNonIpoptException(true);

  // Change some options
  // Note: The following choices are only examples, they might not be
  //       suitable for your optimization problem.
  app->Options()->SetNumericValue("tol", 1e-7);
  app->Options()->SetStringValue("mu_strategy", "adaptive");
  app->Options()->SetStringValue("output_file", "ipopt.out");
  // The following overwrites the default name (ipopt.opt) of the
  // options file
  // app->Options()->SetStringValue("option_file_name", "hs071.opt");

  // Initialize the IpoptApplication and process the options
  ApplicationReturnStatus status;
  status = app->Initialize();
  if (status != Solve_Succeeded) {
    std::cout << std::endl << std::endl << "*** Error during initialization!" << std::endl;
    return (int) status;
  }

  // Ask Ipopt to solve the problem
  status = app->OptimizeTNLP(mynlp);

  if (status == Solve_Succeeded) {
    std::cout << std::endl << std::endl << "*** The problem solved!" << std::endl;
  }
  else {
    std::cout << std::endl << std::endl << "*** The problem FAILED!" << std::endl;
  }

  // As the SmartPtrs go out of scope, the reference count
  // will be decremented and the objects will automatically
  // be deleted.

  return (int) status;
}
コード例 #5
0
bool OptimProblem::solveOptimization(const yarp::sig::Vector& desiredCoM, const yarp::sig::Vector& desiredJoints, std::string feetInContact)
{
    assert(pimpl);
    pimpl->resetOptimizationData(desiredCoM, desiredJoints, feetInContact);

//    // Create a new instance of your nlp
//    //  (use a SmartPtr, not raw)
    SmartPtr<TNLP> mynlp = new Solver(*pimpl);
//
    // Create a new instance of IpoptApplication
    //  (use a SmartPtr, not raw)
    // We are using the factory, since this allows us to compile this
    // example with an Ipopt Windows DLL
    SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
//
//    // Change some options
//    // Note: The following choices are only examples, they might not be
//    //       suitable for your optimization problem.
//    app->Options()->SetNumericValue("tol", 1e-9);
//    app->Options()->SetStringValue("mu_strategy", "adaptive");
//    app->Options()->SetStringValue("output_file", "ipopt.out");
    app->Options()->SetStringValue("hessian_approximation", "limited-memory");
//
//    // Intialize the IpoptApplication and process the options
    ApplicationReturnStatus status;
    status = app->Initialize();
    if (status != Solve_Succeeded) {
        yError("*** Error during initialization of IpOpt!");
        return (int) status;
    }

    // Ask Ipopt to solve the problem
    status = app->OptimizeTNLP(mynlp);

    if (status == Solve_Succeeded) {
        yInfo("*** The problem solved!");
    }
    else {
        yError("*** The problem FAILED!");
    }

    return (int) status;

}
コード例 #6
0
int loadProblem(char *fname,unsigned long len ){
	
	CheckInputArgument(pvApiCtx, 9, 9); // We need total 9 input arguments.
	CheckOutputArgument(pvApiCtx, 1, 1); // Return value will be termination status (0 for no-errors and 1/non-zero for errors)


	double *QItems=NULL,*PItems=NULL,*ConItems=NULL,*conUB=NULL,*conLB=NULL,*varUB=NULL,*varLB=NULL;
	unsigned int nVars,nCons;


	unsigned int arg = 1,temp1,temp2;

	if ( !getIntFromScilab(arg,&nVars) && arg++ && !getIntFromScilab(arg,&nCons) && arg++ &&
		!getDoubleMatrixFromScilab(arg,&temp1,&temp2,&QItems) && temp1 == nVars && temp2 == nVars && arg++ &&
		!getDoubleMatrixFromScilab(arg,&temp1,&temp2,&PItems) && temp2 == nVars && arg++ &&
		!getDoubleMatrixFromScilab(arg,&temp1,&temp2,&ConItems) && temp1 == nCons &&((nCons !=0 && temp2 == nVars)||(temp2==0)) && arg++ &&
		!getDoubleMatrixFromScilab(arg,&temp1,&temp2,&conLB)  && temp2 == nCons && arg++ &&
		!getDoubleMatrixFromScilab(arg,&temp1,&temp2,&conUB)  && temp2 == nCons && arg++ &&
		!getDoubleMatrixFromScilab(arg,&temp1,&temp2,&varLB) && temp2 == nVars && arg++ && 
		!getDoubleMatrixFromScilab(arg,&temp1,&temp2,&varUB) && temp2 == nVars){



		using namespace Ipopt;
		SmartPtr<TNLP> Prob = new QuadNLP(nVars,nCons,QItems,PItems,ConItems,conUB,conLB,varUB,varLB);
		SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
  		app->RethrowNonIpoptException(true);

		// Change some options
		// Note: The following choices are only examples, they might not be
		//       suitable for your optimization problem.
		app->Options()->SetNumericValue("tol", 1e-7);
		app->Options()->SetStringValue("mu_strategy", "adaptive");
		app->Options()->SetStringValue("output_file", "ipopt.out");

		// Indicates whether all equality constraints are linear 
		app->Options()->SetStringValue("jac_c_constant", "yes");
		// Indicates whether all inequality constraints are linear 
		app->Options()->SetStringValue("jac_d_constant", "yes");	
		// Indicates whether the problem is a quadratic problem 
		app->Options()->SetStringValue("hessian_constant", "yes");


		// The following overwrites the default name (ipopt.opt) of the
		// options file
		// app->Options()->SetStringValue("option_file_name", "hs071.opt");
	
		// Initialize the IpoptApplication and process the options
		ApplicationReturnStatus status;
	 	status = app->Initialize();
		if (status != Solve_Succeeded) {
		  	sciprint("\n*** Error during initialization!\n");
			return0toScilab();
	   	 return (int) status;
	 	 }
		 // Ask Ipopt to solve the problem
		 status = app->OptimizeTNLP(Prob);
	
 		if (status == Solve_Succeeded) {
   			sciprint("\n*** The problem solved!\n");
 			 }
  		else {
    			sciprint( "\n*** The problem FAILED!\n");
  			}
	
  		// As the SmartPtrs go out of scope, the reference count
  		// will be decremented and the objects will automatically
  		// be deleted.
	

		}
	else {

		sciprint("\nError:: check argument %d\n",arg);
		return0toScilab();
		return 1;
		}
		
	return0toScilab();
	}
コード例 #7
0
int sci_solveminbndp(char *fname)
{
	using namespace Ipopt;

	CheckInputArgument(pvApiCtx, 5, 5); 
	CheckOutputArgument(pvApiCtx, 9, 9);
	
	// Error management variable
	SciErr sciErr;

	//Function pointers,lower bound and upper bound pointers 
	int* funptr=NULL;
	int* gradhesptr=NULL;
	double* varLB=NULL;
	double* varUB=NULL;

        // Input arguments
	double *cpu_time=NULL,*max_iter=NULL,*tol_val=NULL;
	static unsigned int nVars = 0,nCons = 0;
	unsigned int temp1 = 0,temp2 = 0, iret = 0;
	int x1_rows, x1_cols, x2_rows, x2_cols;
	
	// Output arguments
	double  ObjVal=0,iteration=0,cpuTime=0,fobj_eval=0;
	const double *fX = NULL,*fZl=NULL;
	const double *fZu=NULL;
	double dual_inf, constr_viol, complementarity, kkt_error;
	int rstatus = 0;
	int int_fobj_eval, int_constr_eval, int_fobj_grad_eval, int_constr_jac_eval, int_hess_eval;

	////////// Manage the input argument //////////
	
	//Objective Function
	if(getFunctionFromScilab(1,&funptr))
	{
		return 1;
	}

 	//Function for gradient and hessian
	if(getFunctionFromScilab(2,&gradhesptr))
	{
		return 1;
	}

	//x1(lower bound) matrix from scilab
	if(getDoubleMatrixFromScilab(3, &x1_rows, &x1_cols, &varLB))
	{
		return 1;
	}
     
	//x2(upper bound) matrix from scilab
	if(getDoubleMatrixFromScilab(4, &x2_rows, &x2_cols, &varUB))
	{
		return 1;
	}

    	//Getting number of iterations
    	if(getFixedSizeDoubleMatrixInList(5,2,temp1,temp2,&max_iter))
	{
		return 1;
	}

	//Getting Cpu Time
	if(getFixedSizeDoubleMatrixInList(5,4,temp1,temp2,&cpu_time))
	{
		return 1;
	}

	//Getting Tolerance Value
	if(getFixedSizeDoubleMatrixInList(5,6,temp1,temp2,&tol_val))
	{
		return 1;
	}
 

        //Initialization of parameters
	nVars=x1_rows;
	nCons=0;
        
        // Starting Ipopt

	SmartPtr<minbndNLP> Prob = new minbndNLP(nVars,nCons,varLB,varUB);
	
	SmartPtr<IpoptApplication> app = IpoptApplicationFactory();

	////////// Managing the parameters //////////

	app->Options()->SetNumericValue("tol", *tol_val);
	app->Options()->SetIntegerValue("max_iter", (int)*max_iter);
	app->Options()->SetNumericValue("max_cpu_time", *cpu_time);

	///////// Initialize the IpoptApplication and process the options /////////
	ApplicationReturnStatus status;
 	status = app->Initialize();
	if (status != Solve_Succeeded) {
	  	sciprint("\n*** Error during initialization!\n");
   	 return (int) status;
 	 }
	 // Ask Ipopt to solve the problem
	 status = app->OptimizeTNLP((SmartPtr<TNLP>&)Prob);
	 
	 //Get the solve statistics
	 cpuTime = app->Statistics()->TotalCPUTime();
	 app->Statistics()->NumberOfEvaluations(int_fobj_eval, int_constr_eval, int_fobj_grad_eval, int_constr_jac_eval, int_hess_eval);
	 app->Statistics()->Infeasibilities(dual_inf, constr_viol, complementarity, kkt_error);
	 rstatus = Prob->returnStatus();

	////////// Manage the output argument //////////


	fX = Prob->getX();
	ObjVal = Prob->getObjVal();
	iteration = (double)app->Statistics()->IterationCount();
	fobj_eval=(double)int_fobj_eval;
	fZl = Prob->getZl();
	fZu = Prob->getZu();

	if (returnDoubleMatrixToScilab(1, 1, nVars, fX))
	{
		return 1;
	}

	if (returnDoubleMatrixToScilab(2, 1, 1, &ObjVal))
	{
		return 1;
	}

	if (returnIntegerMatrixToScilab(3, 1, 1, &rstatus))
	{
		return 1;
	}
	
	if (returnDoubleMatrixToScilab(4, 1, 1, &iteration))
	{
		return 1;
	}
		
	if (returnDoubleMatrixToScilab(5, 1, 1, &cpuTime))
	{
		return 1;
	}
	
	if (returnDoubleMatrixToScilab(6, 1, 1, &fobj_eval))
	{
		return 1;
	}
	
	if (returnDoubleMatrixToScilab(7, 1, 1, &dual_inf))
	{
		return 1;
	}

	if (returnDoubleMatrixToScilab(8, 1, nVars, fZl))
	{
		return 1;
	}

	if (returnDoubleMatrixToScilab(9, 1, nVars, fZu))
	{
		return 1;
	}


	return 0;
}
コード例 #8
0
int main(
   int   argv,
   char* argc[]
   )
{
   if( argv == 2 && !strcmp(argc[1], "list") )
   {
      print_problems();
      return 0;
   }

#ifdef TIME_LIMIT
   if (argv==4)
   {
      int runtime = atoi(argc[3]);
      pthread_t thread;
      pthread_create(&thread, NULL, killer_thread, &runtime);
   }
   else
#endif
   if( argv != 3 && argv != 1 )
   {
      printf("Usage: %s (this will ask for problem name)\n", argc[0]);
      printf("       %s ProblemName N\n", argc[0]);
      printf("          where N is a positive parameter determining problem size\n");
      printf("       %s list\n", argc[0]);
      printf("          to list all registered problems.\n");
      return -1;
   }

   SmartPtr<RegisteredTNLP> tnlp;
   Index N;

   if( argv != 1 )
   {
      // Create an instance of your nlp...
      tnlp = RegisteredTNLPs::GetTNLP(argc[1]);
      if( !IsValid(tnlp) )
      {
         printf("Problem with name \"%s\" not known.\n", argc[1]);
         print_problems();
         return -2;
      }

      N = atoi(argc[2]);
   }
   else
   {
      bool done = false;
      while( !done )
      {
         string inputword;
         cout << "Enter problem name (or \"list\" for all available names):\n";
         cin >> inputword;
         if( inputword == "list" )
         {
            print_problems();
         }
         else
         {
            tnlp = RegisteredTNLPs::GetTNLP(inputword.c_str());
            if( !IsValid(tnlp) )
            {
               printf("Problem with name \"%s\" not known.\n", inputword.c_str());
            }
            else
            {
               done = true;
            }
         }
      }
      cout << "Enter problem size:\n";
      cin >> N;
   }

   if( N <= 0 )
   {
      printf("Given problem size is invalid.\n");
      return -3;
   }

   bool retval = tnlp->InitializeProblem(N);
   if( !retval )
   {
      printf("Cannot initialize problem.  Abort.\n");
      return -4;
   }

   // Create an instance of the IpoptApplication
   // We are using the factory, since this allows us to compile this
   // example with an Ipopt Windows DLL
   SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
   ApplicationReturnStatus status;
   status = app->Initialize();
   if( status != Solve_Succeeded )
   {
      printf("\n\n*** Error during initialization!\n");
      return (int) status;
   }
   // Set option to use internal scaling
   // DOES NOT WORK FOR VLUKL* PROBLEMS:
   // app->Options()->SetStringValueIfUnset("nlp_scaling_method", "user-scaling");

   status = app->OptimizeTNLP(GetRawPtr(tnlp));

   return (int) status;
}
コード例 #9
0
ファイル: ampl_ipopt.cpp プロジェクト: ChinaQuants/Ipopt
int main(int argc, char**args)
{
  using namespace Ipopt;

  SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
  app->RethrowNonIpoptException(false);

  // Check if executable is run only to print out options documentation
  if (argc == 2) {
    bool print_options = false;
    bool print_latex_options = false;
    if (!strcmp(args[1],"--print-options")) {
      print_options = true;
    }
    else if (!strcmp(args[1],"--print-latex-options")) {
      print_options = true;
      print_latex_options = true;
    }
    if (print_options) {
      SmartPtr<OptionsList> options = app->Options();
      options->SetStringValue("print_options_documentation", "yes");
      if (print_latex_options) {
        options->SetStringValue("print_options_latex_mode", "yes");
      }
      app->Initialize("");
      return 0;
    }
  }

  // Call Initialize the first time to create a journalist, but ignore
  // any options file
  ApplicationReturnStatus retval;
  retval = app->Initialize("");
  if (retval != Solve_Succeeded) {
    printf("ampl_ipopt.cpp: Error in first Initialize!!!!\n");
    exit(-100);
  }

  // Add the suffix handler for scaling
  SmartPtr<AmplSuffixHandler> suffix_handler = new AmplSuffixHandler();
  suffix_handler->AddAvailableSuffix("scaling_factor", AmplSuffixHandler::Variable_Source, AmplSuffixHandler::Number_Type);
  suffix_handler->AddAvailableSuffix("scaling_factor", AmplSuffixHandler::Constraint_Source, AmplSuffixHandler::Number_Type);
  suffix_handler->AddAvailableSuffix("scaling_factor", AmplSuffixHandler::Objective_Source, AmplSuffixHandler::Number_Type);
  // Modified for warm-start from AMPL
  suffix_handler->AddAvailableSuffix("ipopt_zL_out", AmplSuffixHandler::Variable_Source, AmplSuffixHandler::Number_Type);
  suffix_handler->AddAvailableSuffix("ipopt_zU_out", AmplSuffixHandler::Variable_Source, AmplSuffixHandler::Number_Type);
  suffix_handler->AddAvailableSuffix("ipopt_zL_in", AmplSuffixHandler::Variable_Source, AmplSuffixHandler::Number_Type);
  suffix_handler->AddAvailableSuffix("ipopt_zU_in", AmplSuffixHandler::Variable_Source, AmplSuffixHandler::Number_Type);

  SmartPtr<TNLP> ampl_tnlp = new AmplTNLP(ConstPtr(app->Jnlst()),
                                          app->Options(),
                                          args, suffix_handler);

  // Call Initialize again to process output related options
  retval = app->Initialize();
  if (retval != Solve_Succeeded) {
    printf("ampl_ipopt.cpp: Error in second Initialize!!!!\n");
    exit(-101);
  }

  const int n_loops = 1; // make larger for profiling
  for (Index i=0; i<n_loops; i++) {
    retval = app->OptimizeTNLP(ampl_tnlp);
  }

  // finalize_solution method in AmplTNLP writes the solution file

  return 0;
}
コード例 #10
0
int main(int argv, char* argc[])
{

    mpi_check(MPI_Init(&argv, &argc));

    // identify the process
    char hostname[256];
    gethostname(hostname, sizeof(hostname));
    printf("Process with PID %d on %s ready to run\n", getpid(), hostname);
    fflush(stdout);

    int mpi_rank, mpi_size;
    MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
    MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);

    Index N = -1;
    Index NS = -1;
    if(argv == 3)
    {
        N = atoi(argc[1]);
        NS = atoi(argc[2]);
    } 

    // if rank == MASTER
    if(mpi_rank == 0)
    {

        if (argv != 3) {
            cout << "Usage: $mpirun -n NP ./solve_problem N NS ";
            return 0;
        }

        // Create an instance of your nlp...
        SmartPtr<MittelmannBndryCntrlDiri1> tnlp = new MittelmannBndryCntrlDiri1();


        if (N <= 0 || NS <= 0) {
            printf("Given problem size is invalid.\n");
            return -3;
        }

        bool retval = tnlp->InitializeProblem(N, NS);
        if (!retval) {
            printf("Cannot initialize problem.  Abort.\n");
            return -4;
        }

        // Create an instance of the IpoptApplication
        // We are using the factory, since this allows us to compile this
        // example with an Ipopt Windows DLL
        SmartPtr<IpoptApplication> app = IpoptApplicationFactory();

        app->Options()->SetNumericValue("tol", 1e-7);
        app->Options()->SetStringValue("mu_strategy", "adaptive");
        app->Options()->SetStringValue("output_file", "ipopt.out");
        app->Options()->SetIntegerValue("problem_dimension", N);
        app->Options()->SetIntegerValue("problem_scenarios", NS);

        // const std::string prefix = ""; Index nl;
        // cout << "Retval:" << app->Options()->GetIntegerValue("problem_dimension", nl, prefix) << endl;
        // cout << "problem_dimension: " << nl << endl;

        ApplicationReturnStatus status = app->Initialize();
        if (status != Solve_Succeeded) {
            printf("\n\n*** Error during initialization!\n");
            return (int) status;
        }
        // Set option to use internal scaling
        // DOES NOT WORK FOR VLUKL* PROBLEMS:
        // app->Options()->SetStringValueIfUnset("nlp_scaling_method", "user-scaling");

        status = app->OptimizeTNLP(GetRawPtr(tnlp));
    }
    else
    {
        // child process waits for master to initiate the solution phase
        int pardiso_mtype = -2; // symmetric H_i
        int schur_factorization = 1; //augmented factorization
        SchurSolve schurSolver = SchurSolve(pardiso_mtype, schur_factorization, MPI_COMM_WORLD);
        schurSolver.initSystem_OptimalControl(NULL, N, NS);
        
        while(1) {
            //do test on termination, set by master process
            int terminate = 0;
            MPI_Bcast(&terminate, 1, MPI_INT, 0, MPI_COMM_WORLD);
            if (terminate)
                break;
            
            //get flag new_matrix to child processes
            bool new_matrix;
            MPI_Bcast(&new_matrix, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD);

            //update system if necessary
            if(new_matrix)
            {
                schurSolver.updateSystem(NULL);
            }

            int nrhs = 1;
            schurSolver.solveSystem(NULL, NULL, nrhs);
        }
    }

    mpi_check(MPI_Finalize());

    return 0;
}
コード例 #11
0
ファイル: genome_ipopt_main.cpp プロジェクト: sirusb/pastis
int main(int argc, char* argv[])
{

    get_arguments (argc, argv);

    // figure out which chromosomes I want
    for (int i=0; i < num_chroms; i++)
    {
        chromosome[i] = 0;
    }
    char *token;
    //char locus_coord[] = "locus_coord.txt";
    
    token = strtok(chrom_string,",");
    while (token != NULL)
    {
        int index = atoi(token) - 1;
        chromosome[index] = 1;
        token = strtok(NULL,",");
    }

    // the max_dist is per kb, so adjust it so that it depends on the resolution
    max_dist = max_dist * bp_per_locus / 1000.0;
    // same for min_dist
    min_dist = min_dist * bp_per_locus / 1000.0;

    // Create a new instance of your nlp
    GENOME *mygenome = new GENOME(bp_per_locus, min_dist, max_dist,
                                  interactions_filename, chromosome, add_rDNA,
                                  rDNA_interactions_filename, use_weights,
                                  unseen_interactions_filename,
                                  frequencies_distances_filename,
                                  structure_filename);

    // If a temporary pdb file exists, upload it and initialize the problem
    // there

    char temp_filename[1000];
    sprintf(temp_filename, "%s.temp.txt", output_pdb);
    FILE* file = fopen(temp_filename, "r");
    if(file == 0){
      printf("No temporary file - starting optimization from scratch\n");
    }else{
      fclose(file);
      mygenome->read_txt_input(temp_filename);
    }

    if (strcmp (input_txt, "") != 0)
    {
        printf ("Reading the txt input\n");
        mygenome->read_txt_input(input_txt);
        mygenome->print_pdb_genome(output_pdb);
        if(strcmp(locus_coord,"") != 0){
            mygenome->print_1D_3D_genome(locus_coord);
        }
        return 1;
    }
    else if (strcmp (output_binary_diffusion, "") != 0)
    {
        mygenome->save_adjacency_matrix_for_diffusion(
                output_binary_diffusion,
                diffusion_operation_type);
        return 1;
    }
    else if (strcmp (output_cplex_input, "") != 0)
    // just write the .lp file for cplex
    {
        SmartPtr<genome_ipopt_nlp> mynlp = new genome_ipopt_nlp(
                                                  mygenome, min_clash_dist,
                                                  min_clash_dist_inter,
                                                  output_pdb, sphere_radius,
                                                  use_weights, bp_per_locus,
                                                  rDNA_frequency_normalizer,
                                                  weight_of_inter,
                                                  weight_unseen, true,
                                                  alpha, beta, locus_coord);
        mynlp->write_cplex_input (output_cplex_input);
        return 1;
    }
    else if (strcmp (input_cplex_output, "") != 0)
    // read the file in .sol format (cplex output) and write a pdb file
    {
        mygenome->read_cplex_output(input_cplex_output);
        mygenome->print_pdb_genome(output_pdb);
        if(strcmp (locus_coord,"") != 0){
            mygenome->print_1D_3D_genome(locus_coord);
        }
        return 1;
    }
  //mygenome->save_interaction_adjacency_matrix (initial_interaction_matrix);
  //mygenome->print_pdb_genome (initial_pdb);

  // FIXME we haven't interfaced many of the options.
  SmartPtr<TNLP> mynlp = new genome_ipopt_nlp(
                              mygenome, min_clash_dist, min_clash_dist_inter,
                              output_pdb, sphere_radius, use_weights,
                              bp_per_locus, rDNA_frequency_normalizer,
                              weight_of_inter, weight_unseen, true, alpha, beta, locus_coord
                              );

  // Create a new instance of IpoptApplication
  //  (use a SmartPtr, not raw)
  SmartPtr<IpoptApplication> app = new IpoptApplication();

  // Change some options
  // Note: The following choices are only examples, they might not be
  //       suitable for your optimization problem.
  app->Options()->SetNumericValue("tol", 1e-1);
  app->Options()->SetNumericValue("acceptable_tol", 1e-1);
  // I'm going to set the constraint violation to very very high.
  app->Options()->SetNumericValue("constr_viol_tol", 1e10);
  app->Options()->SetNumericValue("mu_init", 0.0001);
  // This is super high. It should not impact the results
  app->Options()->SetNumericValue("dual_inf_tol", 10000);
  app->Options()->SetNumericValue("compl_inf_tol", 1000000);
  // This should be zero.
  app->Options()->SetIntegerValue("acceptable_iter", 0);

  app->Options()->SetIntegerValue("max_iter", 100000);

  //app->Options()->SetStringValue("mu_strategy", "monotone");
  app->Options()->SetStringValue("mu_strategy", "adaptive");
  app->Options()->SetStringValue("output_file", logging_filename);
  app->Options()->SetStringValue("hessian_approximation", "limited-memory");

  // The following overwrites the default name (ipopt.opt) of the
  // options file
  // app->Options()->SetStringValue("option_file_name", "hs071.opt");

  // Intialize the IpoptApplication and process the options
  ApplicationReturnStatus status;
  status = app->Initialize();
  if (status != Solve_Succeeded) {
    printf("\n\n*** Error during initialization!\n");
    return (int) status;
  }

  // Ask Ipopt to solve the problem
  status = app->OptimizeTNLP(mynlp);

  if (status == Solve_Succeeded || status == Solved_To_Acceptable_Level) {
    printf("\n\n*** The problem solved!\n");
  }
  else {
    printf("\n\n*** The problem FAILED!\n");
    exit(1);
  }

  // As the SmartPtrs go out of scope, the reference count
  // will be decremented and the objects will automatically
  // be deleted.

  return 1;     //(int) status;

}