Skip to content

Commit

Permalink
Restructuring and typo fix suggested by Bryn.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlesnick committed Jun 22, 2018
1 parent 2c74a03 commit 2c2a791
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 71 deletions.
149 changes: 78 additions & 71 deletions computation.cpp
Expand Up @@ -56,90 +56,22 @@ std::unique_ptr<ComputationResult> Computation::compute_raw(ComputationInput& in
}
}

//STAGE 3: COMPUTE MINIMAL PRESENTTION AND MULTIGRADED BETTI NUMBERS
//STAGE 3: COMPUTE MINIMAL PRESENTATION AND MULTIGRADED BETTI NUMBERS

std::unique_ptr<ComputationResult> result(new ComputationResult);

MultiBetti mb(input.rep());

Timer timer;
Timer timer_sub;
timer.restart();
timer_sub.restart();

Presentation pres;

// If the --koszul flag is not given, then we compute Betti numbers by
//computing a minimal presentation
if (!koszul)
{
if (verbosity >= 2) {
debug() << "COMPUTING MINIMAL PRESENTATION:";
}

//Because the assignment operator for the unsigned_matrix class doesn't work properly,
//have to resize the object by hand before assignment.
pres.hom_dims.resize(boost::extents[input.x_exact.size()][input.y_exact.size()]);

pres = Presentation(input.rep(),progress,verbosity);

if (verbosity >= 2) {
std::cout << "COMPUTED (UNMINIMIZED) PRESENTATION!" << std::endl;
std::cout << "Unminimized presentation has " << pres.row_ind.last()+1 << " rows and " << pres.col_ind.last()+1 << " cols." <<std::endl;
}

if (verbosity >= 4) {
std::cout << " --> computing the unminimized presentation took "
<< timer_sub.elapsed() << " milliseconds" << std::endl;
}

if (verbosity > 7)
{
std::cout << "UNMINIMIZED PRESENTATION: " << std::endl;
pres.print();
}

timer_sub.restart();

pres.minimize(verbosity);

if (verbosity >= 2) {
std::cout << "COMPUTED MINIMAL PRESENTATION!" << std::endl;
std::cout << "Minimal presentation has " << pres.row_ind.last()+1 << " rows and " << pres.col_ind.last()+1 << " cols." <<std::endl;
}

if (verbosity >= 4) {
std::cout << " --> minimizing the presentation took "
<< timer_sub.elapsed() << " milliseconds" << std::endl;
}

if (verbosity > 7)
{
std::cout << "MINIMAL PRESENTATION: " << std::endl;
pres.print();
}

progress.progress(95);

mb.read_betti(pres);
mb.compute_xi2(pres.hom_dims);

//TODO: In the new code, the Presentation class keeps its own public
//hom_dims matrix, so the one stored by the object named "result" is no
//longer necessary. However, for compatibility with the old Betti
//number algorithm, for now I am keeping the latter. A more uniform way
//to do this would be to also make the hom_dims a public member of
//MultiBetti.

//NOTE: The boost matrix package actually requires to resize the matrix
//before assignment.
result->homology_dimensions.resize(boost::extents[pres.col_ind.width()][pres.col_ind.height()]);
result->homology_dimensions = pres.hom_dims;

//Now that I've copied the hom_dims matrix, I might as well make the
//original one trivial.
pres.hom_dims.resize(boost::extents[0][0]);

compute_min_pres_and_betti_nums(input,mb,pres,result);
}

// If --koszul flag is given, then we use the old Betti number computation
Expand All @@ -152,7 +84,6 @@ std::unique_ptr<ComputationResult> Computation::compute_raw(ComputationInput& in
mb.compute_koszul(input.rep(),result->homology_dimensions, progress);

mb.compute_xi2(result->homology_dimensions);

}


Expand Down Expand Up @@ -249,3 +180,79 @@ std::unique_ptr<ComputationResult> Computation::compute(InputData data, bool kos
//debug() << "Computing from raw data";
return compute_raw(input, koszul);
}

void Computation::compute_min_pres_and_betti_nums(ComputationInput& input, MultiBetti& mb, Presentation& pres,std::unique_ptr<ComputationResult>& result)
{
Timer timer_sub;
timer_sub.restart();

if (verbosity >= 2) {
debug() << "COMPUTING MINIMAL PRESENTATION:";
}

//Because the assignment operator for the unsigned_matrix class doesn't work properly,
//have to resize the object by hand before assignment.
pres.hom_dims.resize(boost::extents[input.x_exact.size()][input.y_exact.size()]);

pres = Presentation(input.rep(),progress,verbosity);

if (verbosity >= 2) {
std::cout << "COMPUTED (UNMINIMIZED) PRESENTATION!" << std::endl;
std::cout << "Unminimized presentation has " << pres.row_ind.last()+1 << " rows and " << pres.col_ind.last()+1 << " cols." <<std::endl;
}

if (verbosity >= 4) {
std::cout << " --> computing the unminimized presentation took "
<< timer_sub.elapsed() << " milliseconds" << std::endl;
}

if (verbosity > 7)
{
std::cout << "UNMINIMIZED PRESENTATION: " << std::endl;
pres.print();
}

timer_sub.restart();

pres.minimize(verbosity);

if (verbosity >= 2) {
std::cout << "COMPUTED MINIMAL PRESENTATION!" << std::endl;
std::cout << "Minimal presentation has " << pres.row_ind.last()+1 << " rows and " << pres.col_ind.last()+1 << " cols." <<std::endl;
}

if (verbosity >= 4) {
std::cout << " --> minimizing the presentation took "
<< timer_sub.elapsed() << " milliseconds" << std::endl;
}

if (verbosity > 7)
{
std::cout << "MINIMAL PRESENTATION: " << std::endl;
pres.print();
}

progress.progress(95);

mb.read_betti(pres);
mb.compute_xi2(pres.hom_dims);

//TODO: In the new code, the Presentation class keeps its own public
//hom_dims matrix, so the one stored by the object named "result" is no
//longer necessary. However, for compatibility with the old Betti
//number algorithm, for now I am keeping the latter. A more uniform way
//to do this would be to also make the hom_dims a public member of
//MultiBetti.

//NOTE: The boost matrix package actually requires to resize the matrix
//before assignment.
result->homology_dimensions.resize(boost::extents[pres.col_ind.width()][pres.col_ind.height()]);
result->homology_dimensions = pres.hom_dims;

//Now that I've copied the hom_dims matrix, I might as well make the
//original one trivial.
pres.hom_dims.resize(boost::extents[0][0]);
}



5 changes: 5 additions & 0 deletions computation.h
Expand Up @@ -35,6 +35,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <interface/progress.h>
#include <vector>

class Presentation;
class MultiBetti;

//TODO: Remove either this or InputData, since there's no need for both anymore now that RIVET_0 files aren't supported.
class ComputationInput {
protected:
Expand Down Expand Up @@ -96,4 +99,6 @@ class Computation {
const int verbosity;

std::unique_ptr<ComputationResult> compute_raw(ComputationInput& input, bool koszul);

void compute_min_pres_and_betti_nums(ComputationInput& input, MultiBetti& mb, Presentation& pres, std::unique_ptr<ComputationResult>& result);
};

0 comments on commit 2c2a791

Please sign in to comment.