本文整理汇总了C++中SmartPtr::Initialize方法的典型用法代码示例。如果您正苦于以下问题:C++ SmartPtr::Initialize方法的具体用法?C++ SmartPtr::Initialize怎么用?C++ SmartPtr::Initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmartPtr
的用法示例。
在下文中一共展示了SmartPtr::Initialize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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: main
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: main
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: main
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: solveOptimization
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: loadProblem
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: sci_solveminbndp
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);
//.........这里部分代码省略.........
示例8: main
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;
}
示例9: main
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);
//.........这里部分代码省略.........
示例10: main
//.........这里部分代码省略.........
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;
}