Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Refactor to separate header
Browse files Browse the repository at this point in the history
  • Loading branch information
shueja committed Nov 14, 2023
1 parent a349a70 commit 207ee85
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
31 changes: 31 additions & 0 deletions src/optimization/CasADiIterCallback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "casadi/casadi.hpp"
using namespace casadi;
class CasADiIterCallback : public Callback {
// Data members
double d;
public:
// Constructor
CasADiIterCallback(const std::string& name, double d,
const Dict& opts=Dict()) : d(d) {
construct(name, opts);
}

// Destructor
~CasADiIterCallback() override {}

// Number of inputs and outputs
casadi_int get_n_in() override { return 1;}
casadi_int get_n_out() override { return 1;}

// Initialize the object
void init() override() {
std::cout << "initializing object" << std::endl;
}

// Evaluate numerically
std::vector<DM> eval(const std::vector<DM>& arg) const override {
DM x = arg.at(0);
DM f = sin(d*x);
return 1;
}
};
1 change: 1 addition & 0 deletions src/optimization/CasADiOpti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#ifdef OPTIMIZER_BACKEND_CASADI
#include "optimization/CasADiOpti.h"
#include "optimization/CasADiIterCallback.h"

#include <casadi/casadi.hpp>
#include <casadi/core/exception.hpp>
Expand Down
30 changes: 0 additions & 30 deletions src/optimization/CasADiOpti.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,6 @@

namespace trajopt {

class CasADiIterCallback : public Callback {
// Data members
double d;
public:
// Constructor
CasADiIterCallback(const std::string& name, double d,
const Dict& opts=Dict()) : d(d) {
construct(name, opts);
}

// Destructor
~CasADiIterCallback() override {}

// Number of inputs and outputs
casadi_int get_n_in() override { return 1;}
casadi_int get_n_out() override { return 1;}

// Initialize the object
void init() override() {
std::cout << "initializing object" << std::endl;
}

// Evaluate numerically
std::vector<DM> eval(const std::vector<DM>& arg) const override {
DM x = arg.at(0);
DM f = sin(d*x);
return {f};
}
};

class CasADiOpti {
private:
casadi::Opti opti;
Expand Down

0 comments on commit 207ee85

Please sign in to comment.