/[ascend]/trunk/solvers/ipopt/asc_ipopt.c
ViewVC logotype

Contents of /trunk/solvers/ipopt/asc_ipopt.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1529 - (show annotations) (download) (as text)
Thu Jul 5 08:19:02 2007 UTC (16 years, 5 months ago) by jpye
File MIME type: text/x-csrc
File size: 4465 byte(s)
Making build of IPOPT dependent on config test.
1 /* ASCEND modelling environment
2 Copyright (C) 2007 Carnegie Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 *//**
19 @file
20 Connection of the IPOPT optimisation solver into ASCEND.
21
22 THIS IS STILL VERY MUCH UNDER DEVELOPMENT AND INCOMPLETE. I'VE ACTUALLY
23 ONLY JUST STARTED WRITING IT by starting with asc_tron.c and modifying.
24
25 The IPOPT solver is documented at http://www.coin-or.org/Ipopt/
26 *//*
27 ASCEND wrapper for IPOPT originally by John Pye, Jun 2007.
28 */
29
30 #include <utilities/config.h>
31
32 #ifndef WITH_IPOPT
33 # error "WITH_IPOPT must be defined in order to build this."
34 #endif
35
36 #include <solver/solver.h>
37
38 #include <ipopt/IpStdCInterface.h>
39
40 ASC_DLLSPEC SolverRegisterFn ipopt_register;
41
42 #if 0
43 // sample code for the C interface
44
45 int main(){
46 Index n=-1; /* number of variables */
47 Index m=-1; /* number of constraints */
48 Number* x_L = NULL; /* lower bounds on x */
49 Number* x_U = NULL; /* upper bounds on x */
50 Number* g_L = NULL; /* lower bounds on g */
51 Number* g_U = NULL; /* upper bounds on g */
52 IpoptProblem nlp = NULL; /* IpoptProblem */
53 enum ApplicationReturnStatus status; /* Solve return code */
54 Number* x = NULL; /* starting point and solution vector */
55 Number* mult_x_L = NULL; /* lower bound multipliers
56 at the solution */
57 Number* mult_x_U = NULL; /* upper bound multipliers
58 at the solution */
59 Number obj; /* objective value */
60 Index i; /* generic counter */
61
62 /* set the number of variables and allocate space for the bounds */
63 n=4;
64 x_L = (Number*)malloc(sizeof(Number)*n);
65 x_U = (Number*)malloc(sizeof(Number)*n);
66 /* set the values for the variable bounds */
67 for (i=0; i<n; i++) {
68 x_L[i] = 1.0;
69 x_U[i] = 5.0;
70 }
71
72 /* set the number of constraints and allocate space for the bounds */
73 m=2;
74 g_L = (Number*)malloc(sizeof(Number)*m);
75 g_U = (Number*)malloc(sizeof(Number)*m);
76 /* set the values of the constraint bounds */
77 g_L[0] = 25; g_U[0] = 2e19;
78 g_L[1] = 40; g_U[1] = 40;
79
80 /* create the IpoptProblem */
81 nlp = CreateIpoptProblem(n, x_L, x_U, m, g_L, g_U, 8, 10, 0,
82 &eval_f, &eval_g, &eval_grad_f,
83 &eval_jac_g, &eval_h);
84
85 /* We can free the memory now - the values for the bounds have been
86 copied internally in CreateIpoptProblem */
87 free(x_L);
88 free(x_U);
89 free(g_L);
90 free(g_U);
91
92 /* set some options */
93 AddIpoptNumOption(nlp, "tol", 1e-9);
94 AddIpoptStrOption(nlp, "mu_strategy", "adaptive");
95
96 /* allocate space for the initial point and set the values */
97 x = (Number*)malloc(sizeof(Number)*n);
98 x[0] = 1.0;
99 x[1] = 5.0;
100 x[2] = 5.0;
101 x[3] = 1.0;
102
103 /* allocate space to store the bound multipliers at the solution */
104 mult_x_L = (Number*)malloc(sizeof(Number)*n);
105 mult_x_U = (Number*)malloc(sizeof(Number)*n);
106
107 /* solve the problem */
108 status = IpoptSolve(nlp, x, NULL, &obj, NULL, mult_x_L, mult_x_U, NULL);
109
110 if (status == Solve_Succeeded) {
111 printf("\n\nSolution of the primal variables, x\n");
112 for (i=0; i<n; i++) {
113 printf("x[%d] = %e\n", i, x[i]);
114 }
115
116 printf("\n\nSolution of the bound multipliers, z_L and z_U\n");
117 for (i=0; i<n; i++) {
118 printf("z_L[%d] = %e\n", i, mult_x_L[i]);
119 }
120 for (i=0; i<n; i++) {
121 printf("z_U[%d] = %e\n", i, mult_x_U[i]);
122 }
123
124 printf("\n\nObjective value\n");
125 printf("f(x*) = %e\n", obj);
126 }
127
128 /* free allocated memory */
129 FreeIpoptProblem(nlp);
130 free(x);
131 free(mult_x_L);
132 free(mult_x_U);
133
134 return 0;
135 }
136 #endif
137
138 int ipopt_register(void){
139 ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed to load IPOPT");
140 return 1;
141 /* return solver_register(&tron_internals); */
142 }

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22