Comments (8)
When you create a problem, you assign variable sets like what is shown below with unique names. Then when you add a constraint or cost to the problem it gets linked to the problems variable set. So inside the cost or constraint object you have access to the member function GetVariables()
which gives you access to all variable sets. Then during the solve it will call the GetValues()
and FillJacobianBlock
. I also included an example of a constraint implementation which may help.
Problem nlp;
nlp.AddVariableSet(std::make_shared<ExVariables>("var_set0"));
nlp.AddVariableSet(std::make_shared<ExVariables>("var_set1"));
Example:
https://github.com/tesseract-robotics/trajopt/blob/master/trajopt_ifopt/include/trajopt_ifopt/constraints/joint_velocity_constraint.h
https://github.com/tesseract-robotics/trajopt/blob/master/trajopt_ifopt/src/constraints/joint_velocity_constraint.cpp
from ifopt.
Thank you @Levi-Armstrong. But, as I understand, you are getting the values of the external representation (as a VectorXd). I was hoping I could get the internal representation mentioned in the following code snippet. I'd like to define some x0_ and x1_ as Fourier series, for example, and make use of them inside the Constraint and Cost classes.
// Here is where you can transform the Eigen::Vector into whatever
// internal representation of your variables you have (here two doubles, but
// can also be complex classes such as splines, etc..
void SetVariables(const VectorXd& x) override
{
x0_ = x(0);
x1_ = x(1);
};
from ifopt.
You need to create your own variable set by inheriting from VariableSet like what is shown in this example.
Are you wanting to know how to access the x0_ and x1_ from your cost or constraint function?
from ifopt.
Yes, I already have a variable set, and I wanted to access x0_ and x1_ (two Fourier series in my case) from the constraint set. If it isn't possible, then I fail to see the overall usefulness of x0_ and x1_
from ifopt.
Add two methods to your variable set class getX0()
and getX1()
then in your cost or constraint.
auto my_set = std::dynamic_pointer_cast<MyVariableType>(GetVariables()->GetComponent("var_set1"));
... now call your methods exposing x0_ and x1_
from ifopt.
Thank you, I'll try it out.
from ifopt.
Add two methods to your variable set class
getX0()
andgetX1()
then in your cost or constraint.auto my_set = std::dynamic_pointer_cast<MyVariableType>(GetVariables()->GetComponent("var_set1")); ... now call your methods exposing x0_ and x1_
Thank you very much. It worked like magic. I hadn't heard about dynamic_pointer_cast. I was afraid the solution was something much simpler that I wasn't seeing.
from ifopt.
Yea, I think this is the only option you have if you want implementation specific access.
from ifopt.
Related Issues (20)
- Redundant calls to FillJacobianBlock HOT 11
- Unit tests are broken HOT 1
- ROS 2 Foxy Release? HOT 10
- Question about warm starting HOT 3
- warm start is not supported?
- Request release of latest on ROS Noetic? HOT 3
- The EvaluateCostFunctionGradient numerical difference produces incorrect gradient when using squared cost. HOT 3
- Project status
- ifopt-config.cmake error on Windows HOT 1
- defining equaility constraints
- errors with Snopt 7.7 HOT 2
- Get Iterations History HOT 1
- GetBounds() violation when both boundaries are negative HOT 3
- [Q] Weak solver performance HOT 8
- Using AD Libraries HOT 1
- Is IFOPT thread-safe?
- bad-free error when building with memory sanitizer flag
- Disabling solution summary. HOT 1
- I have add a GetHession function to this library. Does anyone know how I should submit to the library owner HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ifopt.