Skip to content

Commit

Permalink
Finished dijkstras
Browse files Browse the repository at this point in the history
  • Loading branch information
okkevaneck committed Nov 22, 2022
1 parent 898e25d commit 1bab279
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
Binary file modified archives/prospr_core.tar.gz
Binary file not shown.
Binary file modified archives/prospr_core.zip
Binary file not shown.
22 changes: 11 additions & 11 deletions prospr/core/src/dijkstra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ struct Conformation {
std::vector<int> one_dim (this->hash.size(), -1);

/* Limit directions to -1 and -2 until a bend at -2 has been made. */
if (this->hash == one_dim || std::find(this->hash.begin(), this->hash.end(), -2) == this->hash.end()) {
auto goes_down = std::find(this->hash.begin(), this->hash.end(), -2);
if (this->hash == one_dim || goes_down == this->hash.end()) {
std::vector<int> neg_moves(dim);
std::iota(neg_moves.begin(), neg_moves.end(), -dim);
return neg_moves;
Expand Down Expand Up @@ -76,8 +77,10 @@ struct Conformation {
/* Overload > operator for Conformation in the priority queue.
* Bigger indicates more potential for leading towards the minimum energy conformation.
*/
bool operator>(const struct Conformation& conf1, const struct Conformation& conf2) {
return conf1.score > conf2.score || (conf1.score == conf2.score && conf1.length > conf2.length);
bool operator>(const struct Conformation& conf1,
const struct Conformation& conf2) {
return conf1.score > conf2.score ||
(conf1.score == conf2.score && conf1.length > conf2.length);
}

/* Overload << operator for printing Conformations. */
Expand All @@ -103,8 +106,10 @@ Protein* dijkstra(Protein* protein) {
return protein;
}

/* Make priority queue sorting first on lowest energy, then on smallest length. */
std::priority_queue<Conformation, std::vector<Conformation>, std::greater<Conformation>> prioq;
/* Make priority queue, sorting on lowest energy, then on length. */
std::priority_queue<Conformation,
std::vector<Conformation>,
std::greater<Conformation>> prioq;
std::vector<Conformation> children;

/* Add initial partial conformation as only node in priority queue. */
Expand All @@ -122,15 +127,11 @@ Protein* dijkstra(Protein* protein) {
conf = prioq.top();
prioq.pop();

std::cout << "\nCur pop: " << conf << "\n";

/* Create children of current conformation and loop over them. */
children = conf.create_children(protein);

for (Conformation conf : children) {
std::cout << "\t" << conf << "\n";

/* If child is complete conformation, check stability for new best. */
/* If child is complete conformation, check for new best. */
if (conf.hash.size() == max_length - 1) {
protein->set_hash(conf.hash);

Expand All @@ -145,7 +146,6 @@ Protein* dijkstra(Protein* protein) {
}
}

std::cout << "\n\nBest found conformation:\n" << best_conf << "\n";
protein->set_hash(best_conf.hash);

return protein;
Expand Down
6 changes: 2 additions & 4 deletions prospr/core/tests/test_algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ void test_depth_first_bnb() {
/* Test functionality of depth_first_bnb. */
void test_dijkstra() {
/* Check if 2D solutions are found correctly. */
// Protein* protein = new Protein("PHPHPHPPH", 2, "HP");
Protein* protein = new Protein("HPPH", 2, "HP");
Protein* protein = new Protein("PHPHPHPPH", 2, "HP");
protein = dijkstra(protein);
// assert (protein->get_score() == -3);
assert (protein->get_score() == -1);
assert (protein->get_score() == -3);
std::cout << "\t2D Protein solution scores matches.\n";

/* Check if 3D solutions are found correctly. */
Expand Down

0 comments on commit 1bab279

Please sign in to comment.