Skip to content

Commit

Permalink
last progress with marco
Browse files Browse the repository at this point in the history
  • Loading branch information
migp11 committed Oct 22, 2024
1 parent d434b0e commit b04610a
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 585 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ physiboss-cell-lines-sample:
ecoli-acetic-switch-sample:
cp ./sample_projects_intracellular/fba/ecoli_acetic_switch/custom_modules/* ./custom_modules/
touch main.cpp && cp main.cpp main-backup.cpp
cp ./sample_projects_intracellular/fba/ecoli_acetic_switch/main_ecoli_acetic_switch.cpp ./main.cpp
cp ./sample_projects_intracellular/fba/ecoli_acetic_switch/main.cpp ./main.cpp
cp Makefile Makefile-backup
cp ./sample_projects_intracellular/fba/ecoli_acetic_switch/Makefile ./
cp ./config/PhysiCell_settings.xml ./config/PhysiCell_settings-backup.xml
Expand Down
39 changes: 22 additions & 17 deletions addons/dFBA/src/dfba_Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dFBAModel::~dFBAModel() {
for(dFBAReaction* rxn: this->reactions)
delete rxn;

for(dFBAMetabolite* met: this->metabolites)
for(dFBAMetabolite* met: this->metabolites)
delete met;

if (this->handler != NULL)
Expand Down Expand Up @@ -98,13 +98,13 @@ dFBAReaction* dFBAModel::getReaction(std::string rId)
}


float dFBAModel::getReactionUpperBound(std::string rId)
double dFBAModel::getReactionUpperBound(std::string rId)
{
dFBAReaction* rxn = this->getReaction(rId);
return rxn->getUpperBound();
}

void dFBAModel::setReactionUpperBound(std::string rId, float upperBound)
void dFBAModel::setReactionUpperBound(std::string rId, double upperBound)
{
dFBAReaction* rxn = this->getReaction(rId);
if (rxn)
Expand All @@ -115,13 +115,13 @@ void dFBAModel::setReactionUpperBound(std::string rId, float upperBound)
}
}

float dFBAModel::getReactionLowerBound(std::string rId)
double dFBAModel::getReactionLowerBound(std::string rId)
{
dFBAReaction* rxn = this->getReaction(rId);
return rxn->getLowerBound();
}

void dFBAModel::setReactionLowerBound(std::string rId, float lowerBound)
void dFBAModel::setReactionLowerBound(std::string rId, double lowerBound)
{
dFBAReaction* rxn = this->getReaction(rId);
if (rxn)
Expand Down Expand Up @@ -286,12 +286,11 @@ void dFBAModel::readSBMLModel(const char* sbmlFileName)

void dFBAModel::initProblem()
{

int n_rows = this->getNumMetabolites();
int n_cols = this->getNumReactions();

handler = new CoinMessageHandler(nullptr);

std::cout << "Initilizing LP problem n=" << n_rows << std::endl;
handler->setLogLevel(0);
problem.passInMessageHandler(handler);

Expand Down Expand Up @@ -331,18 +330,19 @@ void dFBAModel::initProblem()
this->problem.loadProblem(matrix, col_lb, col_ub, objective, row_lb, row_ub);
this->problem.setOptimizationDirection(-1);

delete col_lb;
delete col_ub;
delete row_lb;
delete row_ub;
delete objective;
delete[] col_lb;
delete[] col_ub;
delete[] row_lb;
delete[] row_ub;
delete[] objective;

this->is_initialized = true;
}

void dFBAModel::initModel(const char* sbmlFileName)
{
this->readSBMLModel(sbmlFileName);
std::cout << "SBML model correctly loeaded: " << sbmlFileName << std::endl;
this->initProblem();
}

Expand All @@ -353,14 +353,18 @@ void dFBAModel::writeProblem(const char *filename)

dFBASolution dFBAModel::optimize()
{
// std::cout << "Running FBA... ";

std::cout << "Running FBA... " << std::endl;
std::cout << "Status before " << this->problem.statusOfProblem() << std::endl;
this->problem.initialSolve();
this->problem.primal();
std::cout << "Status after running " << this->problem.statusOfProblem() << std::endl;
std::cout << "Before checking... " << std::endl;
if ( problem.isProvenOptimal() )
{
std::cout << "Optimal solution found... ";
const double *columnPrimal = this->problem.getColSolution();
std::map<std::string,float> fluxes;
std::map<std::string,float> reduced_costs;
std::map<std::string,double> fluxes;
std::map<std::string,double> reduced_costs;

std::string status;

Expand Down Expand Up @@ -390,6 +394,7 @@ dFBASolution dFBAModel::optimize()
}
else
{
std::cout << "huston... ";
for(dFBAReaction* reaction: this->reactions)
{ reaction->setFluxValue(0.0); }
}
Expand All @@ -404,7 +409,7 @@ bool dFBAModel::getSolutionStatus()
return false;
}

float dFBAModel::getObjectiveValue()
double dFBAModel::getObjectiveValue()
{
assert(this->is_initialized);
if (this->problem.isProvenOptimal())
Expand Down
10 changes: 5 additions & 5 deletions addons/dFBA/src/dfba_Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ class dFBAModel
const int getReactionIndex(std::string rId);

/** \brief Get the upper bound of a reactions*/
float getReactionUpperBound(std::string rId);
double getReactionUpperBound(std::string rId);

/** \brief Set the upper bound of a reactions*/
void setReactionUpperBound(std::string rId, float upperBound);
void setReactionUpperBound(std::string rId, double upperBound);

/** \brief Get the upper bound of a reactions*/
float getReactionLowerBound(std::string rId);
double getReactionLowerBound(std::string rId);

/** \brief Set the lower bound of a reactions*/
void setReactionLowerBound(std::string rId, float lowerBound);
void setReactionLowerBound(std::string rId, double lowerBound);

/** \brief Get the number of model reactions*/
const int getNumReactions();
Expand Down Expand Up @@ -142,7 +142,7 @@ class dFBAModel
bool getSolutionStatus();

/** \brief Get objective value */
float getObjectiveValue();
double getObjectiveValue();

dFBASolution getSolution(){ return this->solution; }
};
Expand Down
2 changes: 1 addition & 1 deletion addons/dFBA/src/dfba_Solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dFBASolution::dFBASolution()
this->status = "none";
}

dFBASolution::dFBASolution(float objective_value, std::string status, std::map<std::string,float> fluxes)
dFBASolution::dFBASolution(double objective_value, std::string status, std::map<std::string,double> fluxes)
{
this->objective_value = objective_value;
this->status = status;
Expand Down
12 changes: 6 additions & 6 deletions addons/dFBA/src/dfba_Solution.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ class dFBASolution

public:

float objective_value;
double objective_value;
std::string status;
std::map<std::string, float> fluxes;
std::map<std::string, float> reduced_costs;
std::map<std::string, double> fluxes;
std::map<std::string, double> reduced_costs;

dFBASolution();
dFBASolution(float objective_value, std::string status, std::map<std::string,float> fluxes);
dFBASolution(double objective_value, std::string status, std::map<std::string,double> fluxes);
~dFBASolution();

float getObjectiveValue(){ return this->objective_value; }
double getObjectiveValue(){ return this->objective_value; }
std::string getStatus(){ return this->status; };
std::map<std::string, float> getFluxes(){ return fluxes; };
std::map<std::string, double> getFluxes(){ return fluxes; };

};

Expand Down
Loading

0 comments on commit b04610a

Please sign in to comment.