Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
alta
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alta
alta
Commits
12b40171
Commit
12b40171
authored
Sep 18, 2013
by
Laurent Belcour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working Ipopt solver
parent
a4abe2ed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
4 deletions
+42
-4
sources/plugins/nonlinear_fitter_ipopt/fitter.cpp
sources/plugins/nonlinear_fitter_ipopt/fitter.cpp
+42
-4
No files found.
sources/plugins/nonlinear_fitter_ipopt/fitter.cpp
View file @
12b40171
...
...
@@ -121,6 +121,11 @@ class altaNLP : public Ipopt::TNLP
virtual
bool
eval_grad_f
(
Ipopt
::
Index
n
,
const
Ipopt
::
Number
*
x
,
bool
new_x
,
Ipopt
::
Number
*
grad_f
)
{
// Update the parameters vector
vec
_p
(
n
);
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
_p
[
i
]
=
x
[
i
];
}
_f
->
setParameters
(
_p
);
// Clean the value
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
grad_f
[
i
]
=
0.0
;
}
...
...
@@ -128,6 +133,17 @@ class altaNLP : public Ipopt::TNLP
for
(
int
s
=
0
;
s
<
_d
->
size
();
++
s
)
{
vec
_x
=
_d
->
get
(
s
);
// Extract the objective from the current vector
vec
_di
=
vec
(
_f
->
dimY
());
for
(
int
i
=
0
;
i
<
_f
->
dimY
();
++
i
)
{
_di
[
i
]
=
_x
[
_f
->
dimX
()
+
i
];
}
// Compute the difference vector and add its
// components to the obj_value
vec
_y
=
_di
-
(
*
_f
)(
_x
);
// Get the jacobian of the function at position x_i for the current
// set of parameters (set prior to function call)
...
...
@@ -140,7 +156,14 @@ class altaNLP : public Ipopt::TNLP
// vector row
for
(
int
i
=
0
;
i
<
_f
->
dimY
();
++
i
)
{
grad_f
[
j
]
+=
-
_jac
[
i
*
_f
->
nbParameters
()
+
j
];
if
(
_y
[
i
]
>
0.0
)
{
grad_f
[
j
]
+=
-
_jac
[
i
*
_f
->
nbParameters
()
+
j
];
}
else
{
grad_f
[
j
]
+=
_jac
[
i
*
_f
->
nbParameters
()
+
j
];
}
}
}
}
...
...
@@ -179,7 +202,12 @@ class altaNLP : public Ipopt::TNLP
Ipopt
::
Number
obj_value
,
const
Ipopt
::
IpoptData
*
ip_data
,
Ipopt
::
IpoptCalculatedQuantities
*
ip_cq
)
{
// Update the parameters vector
vec
_p
(
n
);
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
_p
[
i
]
=
x
[
i
];
}
_f
->
setParameters
(
_p
);
}
protected:
const
data
*
_d
;
...
...
@@ -248,11 +276,21 @@ bool nonlinear_fitter_ipopt::fit_data(const data* d, function* fit, const argume
{
#ifdef DEBUG
Ipopt
::
Index
iter_count
=
app
->
Statistics
()
->
IterationCount
();
std
::
cout
<<
"<<DEBUG>> number of iterations: "
<<
iter_count
<<
std
::
endl
std
::
cout
<<
"<<DEBUG>> number of iterations: "
<<
iter_count
<<
std
::
endl
;
#endif
std
::
cout
<<
"<<INFO>> found parameters: "
<<
nf
->
parameters
()
<<
std
::
endl
;
return
true
;
}
else
if
(
status
==
Ipopt
::
Maximum_Iterations_Exceeded
)
{
std
::
cout
<<
"<<INFO>> the maximum number of iteration has been reached"
<<
std
::
endl
;
#ifdef DEBUG
Ipopt
::
Index
iter_count
=
app
->
Statistics
()
->
IterationCount
();
std
::
cout
<<
"<<DEBUG>> number of iterations: "
<<
iter_count
<<
std
::
endl
;
#endif
std
::
cout
<<
"<<INFO>> found parameters: "
<<
p
<<
std
::
endl
;
std
::
cout
<<
"<<INFO>> found parameters: "
<<
nf
->
parameters
()
<<
std
::
endl
;
nf
->
setParameters
(
p
);
return
true
;
}
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment