Skip to content

Add method to check component name duplication #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add method to find duplicate component name.
  • Loading branch information
mmurooka committed Dec 10, 2021
commit dfc28854d287fbb5ade3318838f7a630f128eb52
6 changes: 6 additions & 0 deletions ifopt_core/include/ifopt/problem.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ class Problem {
*/
const Composite& GetCosts() const { return costs_; };

/**
* @brief Find duplicate component name
* @return Duplicate component name if found, otherwise empty
*/
std::string FindDuplicateComponentName() const;

private:
Composite::Ptr variables_;
Composite constraints_;
Expand Down
33 changes: 32 additions & 1 deletion ifopt_core/src/problem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ifopt/problem.h>
#include <iostream>
#include <iomanip>
#include <set>


namespace ifopt {
Expand Down Expand Up @@ -221,7 +222,37 @@ Problem::PrintCurrent() const
variables_->PrintAll();
constraints_.PrintAll();
costs_.PrintAll();
};
}

std::string
Problem::FindDuplicateComponentName () const
{
auto check_composite = [](const auto& components, std::string& name) -> bool {
std::set<std::string> names;
for (const auto& c : components) {
if (names.count(c->GetName())) {
name = c->GetName();
return true;
}
names.insert(c->GetName());
}
return false;
};

std::string ret = "";

if (check_composite(variables_->GetComponents(), ret)) {
return ret;
}
if (check_composite(constraints_.GetComponents(), ret)) {
return ret;
}
if (check_composite(costs_.GetComponents(), ret)) {
return ret;
}

return ret;
}

Problem::VectorXd
Problem::ConvertToEigen(const double* x) const
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy