Page 1 of 1

re. constrained optimization

Posted: Fri Sep 18, 2015 7:51 am
by ex10192
Hi,

I am trying to run a constrained forward optimization. I tried to includethe constraint function in the optimization class, but I feel that both the objective function and constraint function are running independent of each other.

My doubt: Do I need to repeat the same steps inside constrained function, similar to the objective function. or is it possible to pass the parameters obtained from objective function directly to the constraint function?

hope someone could find the error and kindly correct me.

thanks

Nithin

Code: Select all

// Example:

class ProblemSystem : public OptimizerSystem {
public:


   int objectiveFunc(  const Vector & newControllerParameters, bool new_coefficients, Real& f ) const {
     // 1 . Updating newControllerParameters for muscle
   //  2. Adding an analysis
    // 3. integrating states
    // 4. From states ( from analysis)  formulate the f (objective function), and get x to minimise
           f =  [x] ;
      return( 0 ); 
   }

  int constraintFunc( const Vector &newControllerParameters, bool new_coefficients, Vector &constraints)  const{

       // 1 . Updating newControllerParameters for muscle
   //  2. Adding an analysis
    // 3. integrating states
    // 4. From analysis, states formulate the f (objective function), and get x 
      
      constraints[0] = x[0] - 25.0;

      return(0);
  }

    ProblemSystem( const int numParams, const int numEqualityConstraints) :
        OptimizerSystem( numParams ) 
    {
        setNumEqualityConstraints( numEqualityConstraints );
       
    }

};














Re: re. constrained optimization

Posted: Fri Sep 18, 2015 12:59 pm
by jp123909
hi,
Very difficult to understand what is your question.
What is [X]?
What is X[0]?
Is X a vector and X[0] is the first element of it?
Are you trying to fix the value of X[0] to 25 at the final time of the simulation? or you are trying to fix it as a constant 25 all the time during the simulation?

best regards
jiang

Re: re. constrained optimization

Posted: Fri Sep 18, 2015 1:24 pm
by ex10192
Hi Jiang,


Sorry, since I put as an example, I didnt go too deep into checking the indexing of the element as I wrote it casually. X is a say the value of power (type-double), which I would like to minimise/maximise. the newcoefficients are Controller for muscles.

Replacing X[0] to a double Y; to avoid confusion,

For the second part, I am trying to fix the equality constrained to a fixed value. So that during optimisation I will be able to obtain a value for Y, ( constraint parameter to use not decided yet) equal to fixed value 25 at all time and doesnt go beyond. So my Overall aim to perform optimization, get the best states and while maintaining the constraints.

if you have doubts just check the document attached. I am just trying to implement it with minor examples.

tks

Re: re. constrained optimization

Posted: Fri Sep 18, 2015 1:48 pm
by jp123909
hi,

Your attachment is good .
Actually I would like to ask if you are conducting forward dynamics simulation in your objective function.
x[0] was constrained to 25 all the time during FD simulation?
or you are not conducting forward dynamics simulation in your objective function? like simple optimization example in OpenSim ApiExamples.

best regards,