Skip to content

Commit

Permalink
[cpp] Smarter max cube count
Browse files Browse the repository at this point in the history
  • Loading branch information
Akodiat committed Aug 8, 2022
1 parent 403c77a commit a967afc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions cpp/src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ std::vector<Rule> parseRules(std::string ruleStr) {

double assembleRatio(Eigen::Matrix3Xf coords, std::string rulestr, int nTries, AssemblyMode assemblyMode, bool ruleIsHex, bool torsion
) {
// Set maxNCubes to the specified number of cubes
int maxNCubes = coords.cols();
int nEqual = 0;
for (int i=0; i<nTries; i++) {
if (checkEquality(rulestr, coords, assemblyMode, ruleIsHex, torsion, maxNCubes)) {
if (checkEquality(rulestr, coords, assemblyMode, ruleIsHex, torsion)) {
nEqual++;
}
}
Expand Down Expand Up @@ -123,11 +121,14 @@ Result runTries(std::string rulestr, int nTries, AssemblyMode assemblyMode, bool
}

// Check if a rule forms a given polycube shape
bool checkEquality(std::string rule, Eigen::Matrix3Xf coords, AssemblyMode assemblyMode, bool ruleIsHex, bool torsion, size_t nMaxCubes) {
bool checkEquality(std::string rule, Eigen::Matrix3Xf coords, AssemblyMode assemblyMode, bool ruleIsHex, bool torsion) {
PolycubeSystem* p = new PolycubeSystem(
ruleIsHex ? parseRules(rule) : parseDecRule(rule),
assemblyMode,
nMaxCubes
// Set nMaxCubes to one more than what we want to check against.
// This way, we don't assemble longer than neccesary, but can also
// rule out detect unbounded rules.
coords.cols() + 1
);
p->setTorsion(torsion);
p->seed();
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ std::vector<Rule> parseDecRule(std::string ruleStr);
std::vector<Rule> parseRules(std::string ruleStr);

bool checkEquality(std::string rule1, std::string rule2, AssemblyMode assemblyMode, bool torsion = true, size_t nMaxCubes = 100);
bool checkEquality(std::string rule, Eigen::Matrix3Xf coords, AssemblyMode assemblyMode, bool ruleIsHex = true, bool torsion = true, size_t nMaxCubes = 100);
bool checkEquality(std::string rule, Eigen::Matrix3Xf coords, AssemblyMode assemblyMode, bool ruleIsHex = true, bool torsion = true);

// Split string, from https://stackoverflow.com/a/10058725
std::vector<std::string> splitString(std::string s, char delim);
Expand Down

0 comments on commit a967afc

Please sign in to comment.