diff options
Diffstat (limited to 'sci-chemistry/ball/files/ball-1.4.1-Fixed-the-FPT-version-of-bond-order-assignment-2.patch')
-rw-r--r-- | sci-chemistry/ball/files/ball-1.4.1-Fixed-the-FPT-version-of-bond-order-assignment-2.patch | 444 |
1 files changed, 444 insertions, 0 deletions
diff --git a/sci-chemistry/ball/files/ball-1.4.1-Fixed-the-FPT-version-of-bond-order-assignment-2.patch b/sci-chemistry/ball/files/ball-1.4.1-Fixed-the-FPT-version-of-bond-order-assignment-2.patch new file mode 100644 index 000000000000..c5d3fddb1b89 --- /dev/null +++ b/sci-chemistry/ball/files/ball-1.4.1-Fixed-the-FPT-version-of-bond-order-assignment-2.patch @@ -0,0 +1,444 @@ + include/BALL/DATATYPE/GRAPH/graphAlgorithms.h | 7 +- + include/BALL/DATATYPE/GRAPH/treeWidth.h | 44 ++++++- + include/BALL/DATATYPE/GRAPH/treeWidth.iC | 145 +++++++++++++-------- + source/DATATYPE/GRAPH/treeWidth.C | 24 ++++ + source/STRUCTURE/BONDORDERS/FPTBondOrderStrategy.C | 12 +- + 5 files changed, 161 insertions(+), 71 deletions(-) + +diff --git a/include/BALL/DATATYPE/GRAPH/graphAlgorithms.h b/include/BALL/DATATYPE/GRAPH/graphAlgorithms.h +index d10de34..5e218ff 100644 +--- a/include/BALL/DATATYPE/GRAPH/graphAlgorithms.h ++++ b/include/BALL/DATATYPE/GRAPH/graphAlgorithms.h +@@ -25,7 +25,7 @@ namespace boost + enum vertex_orig_ptr_t { vertex_orig_ptr }; + + enum edge_bond_ptr_t { edge_bond_ptr }; +- enum edge_orig_ptr_t { edge_orig_ptr }; ++ enum edge_orig_ptr_t { edge_orig_ptr }; + + BOOST_INSTALL_PROPERTY(vertex, atom_ptr); + BOOST_INSTALL_PROPERTY(vertex, orig_ptr); +@@ -150,7 +150,7 @@ namespace BALL + { + bi = ai; ++bi; + for (; bi != ai_end; ++bi) +- if (!boost::edge(*ai, *bi, graph).second) ++ if (*bi != *ai && !boost::edge(*ai, *bi, graph).second) + boost::add_edge(*ai, *bi, graph); + } + +@@ -179,7 +179,6 @@ namespace BALL + + typedef typename boost::property_traits<typename boost::property_map<UndirectedGraph, boost::edge_all_t>::type>::value_type EdgeProperties; + +- EdgeProperties ep = boost::get(boost::edge_all_t(), graph, boost::edge(vertex, *ai, graph).first) ; + result.getEdgeProperties().push_back(boost::get(boost::edge_all_t(), graph, boost::edge(vertex, *ai, graph).first)); + + bi = ai; ++bi; +@@ -189,7 +188,7 @@ namespace BALL + { + boost::add_edge(*ai, *bi, graph); + result.getEdges().push_back(std::make_pair(boost::get(boost::vertex_index, graph, *ai), +- boost::get(boost::vertex_index, graph, *bi))); ++ boost::get(boost::vertex_index, graph, *bi))); + } + } + } +diff --git a/include/BALL/DATATYPE/GRAPH/treeWidth.h b/include/BALL/DATATYPE/GRAPH/treeWidth.h +index dc7cdc5..f7687ef 100644 +--- a/include/BALL/DATATYPE/GRAPH/treeWidth.h ++++ b/include/BALL/DATATYPE/GRAPH/treeWidth.h +@@ -30,10 +30,12 @@ + #include <map> + #include <set> + #include <vector> ++#include <iostream> + + #include <boost/graph/connected_components.hpp> + #include <boost/graph/filtered_graph.hpp> + #include <boost/graph/graph_as_tree.hpp> ++#include <boost/graph/graphviz.hpp> + #include <boost/graph/copy.hpp> + + namespace boost +@@ -91,7 +93,7 @@ namespace BALL + END_BAG + }; + +- typedef typename GRAPH::GraphTraits<UndirectedGraph>::EditableGraph EditableGraph; ++ typedef typename GRAPH::GraphTraits<UndirectedGraph>::EditableGraph EditableGraph; + typedef typename boost::graph_traits<UndirectedGraph>::vertex_descriptor OriginalVertexType; + + typedef std::set<OriginalVertexType> TreeDecompositionContent; +@@ -111,6 +113,16 @@ namespace BALL + + TreeWidth(UndirectedGraph const& input); + ++ /** Compute the tree width of a given tree decomposition. ++ * This function iterates over all nodes in the graph to determine the tree width, ++ * i.e., the (maximum number of vertices over all bags) - 1 ++ */ ++ static Size computeTreeWidth(TreeDecomposition const& td); ++ ++ /** Write a tree decomposition in graphviz format. ++ */ ++ void writeGraphvizFile(std::ostream& out, TreeDecomposition const& td); ++ + std::vector<boost::shared_ptr<EditableGraph> >& getComponents() { return components_; } + std::vector<boost::shared_ptr<TreeDecomposition> >& getNiceTreeDecompositions() { return nice_tree_decompositions_; } + +@@ -120,25 +132,44 @@ namespace BALL + { + public: + ComponentFilter_(ComponentMap cm, Position i) +- : cm_(&cm), ++ : cm_(cm), + component_(i) + { } + + template <typename Vertex> + bool operator() (const Vertex& e) const + { +- return ((*cm_)[e] == component_); ++ return ((cm_)[e] == component_); + } + + protected: +- ComponentMap* cm_; ++ ComponentMap cm_; + Position component_; + }; + ++ /** PropertyWriter for graphviz output. ++ */ ++ class BagContentWriter ++ { ++ public: ++ BagContentWriter(TreeDecomposition const* td, UndirectedGraph const* original_graph) ++ : td_(td), ++ original_graph_(original_graph) ++ { } ++ ++ void operator() (std::ostream& out, const TreeDecompositionBag& v) const; ++ ++ protected: ++ TreeDecomposition const* td_; ++ UndirectedGraph const* original_graph_; ++ }; ++ ++ // TODO: would UndirectedGraph suffice here? + MolecularGraph const* input_; ++ + std::vector<boost::shared_ptr<EditableGraph> > components_; + +- std::vector<boost::shared_ptr<TreeDecomposition> > nice_tree_decompositions_; ++ std::vector<boost::shared_ptr<TreeDecomposition> > nice_tree_decompositions_; + std::vector<boost::shared_ptr<TreeDecompositionGraph> > nice_tree_decomposition_graphs_; + }; + +@@ -397,6 +428,9 @@ namespace BALL + * The bitset remembers the eliminated vertices without an ordering. + */ + BitSet buildBitset() const; ++ ++ protected: ++ std::map<int, VertexType> index_to_vertex_; + }; + + /** +diff --git a/include/BALL/DATATYPE/GRAPH/treeWidth.iC b/include/BALL/DATATYPE/GRAPH/treeWidth.iC +index 633e588..99f14cf 100644 +--- a/include/BALL/DATATYPE/GRAPH/treeWidth.iC ++++ b/include/BALL/DATATYPE/GRAPH/treeWidth.iC +@@ -68,6 +68,34 @@ namespace BALL + } + } + ++ template <class UndirectedGraph> ++ Size TreeWidth<UndirectedGraph>::computeTreeWidth(TreeDecomposition const& td) ++ { ++ Size result = 1; ++ ++ BGL_FORALL_VERTICES_T(current_vertex, td._g, UndirectedGraph) ++ { ++ result = std::max((Size)(boost::get(boost::vertex_bag_content, td, current_vertex).size()), result); ++ } ++ ++ return result - 1; ++ } ++ ++ template <class UndirectedGraph> ++ void TreeWidth<UndirectedGraph>::writeGraphvizFile(std::ostream& out, TreeDecomposition const& td) ++ { ++ boost::write_graphviz(out, td._g, BagContentWriter(&td, input_)); ++ } ++ ++ template <> ++ void TreeWidth<MolecularGraph>::BagContentWriter::operator() (std::ostream& out, const TreeDecompositionBag& v) const; ++ ++ template <class UndirectedGraph> ++ void TreeWidth<UndirectedGraph>::BagContentWriter::operator() (std::ostream& out, const TreeDecompositionBag& v) const ++ { ++ out << "[label=\"" << boost::get(boost::vertex_index, *td_, v) << "\"]"; ++ } ++ + // ***************************************************************************************** + // * TreeWidthImplementation * + // ***************************************************************************************** +@@ -322,8 +350,9 @@ namespace BALL + if (boost::out_degree(vertex, graph_) <= 1) + return IS_SIMPLICIAL; + +- VertexType* n1 = NULL; +- VertexType* n2 = NULL; ++ VertexType n1 = VertexType(); ++ VertexType n2 = VertexType(); ++ bool found_unconnected = false; + + typename boost::graph_traits<UndirectedGraph>::adjacency_iterator a_i, a_j, ai_end; + +@@ -337,20 +366,21 @@ namespace BALL + + if (!boost::edge(i, j, graph_).second) + { +- if (!n1) ++ if (!found_unconnected) + { +- n1 = &i; +- n2 = &j; ++ n1 = i; ++ n2 = j; ++ found_unconnected = true; + } +- else if (i == *n1 || i == *n2) ++ else if (i == n1 || i == n2) + { +- n1 = &i; +- n2 = &i; ++ n1 = i; ++ n2 = i; + } +- else if (j == *n1 || j == *n2) ++ else if (j == n1 || j == n2) + { +- n1 = &j; +- n2 = &j; ++ n1 = j; ++ n2 = j; + } + else + { +@@ -376,11 +406,10 @@ namespace BALL + { + Size nxt = cstate.permutation.size(); + +- std::map<int, VertexType> index_to_vertex; + BGL_FORALL_VERTICES_T(current_vertex, graph_, UndirectedGraph) + { + Size index = boost::get(boost::vertex_index, graph_, current_vertex); +- index_to_vertex[index] = current_vertex; ++ index_to_vertex_[index] = current_vertex; + SIMPLICIAL_TYPE simplicial(isSimplicial(current_vertex)); + if (simplicial == IS_SIMPLICIAL || simplicial == ALMOST_SIMPLICIAL) + { +@@ -388,14 +417,13 @@ namespace BALL + } + } + +- +- for (typename std::vector<Size>::const_iterator st_iter = cstate.permutation.begin() + nxt; +- st_iter != cstate.permutation.end(); ++st_iter) ++ for (typename std::vector<Size>::const_iterator st_iter = cstate.permutation.begin() + nxt; ++ st_iter != cstate.permutation.end(); ++ ++st_iter) + { +- VertexType vertex = index_to_vertex[*st_iter]; ++ VertexType vertex = index_to_vertex_[*st_iter]; + cstate.g = std::max(cstate.g, (Size)boost::out_degree(vertex, graph_)); + cstate.f = std::max(cstate.f, cstate.g); +- + GRAPH::eliminateVertex(vertex, graph_); + } + } +@@ -459,55 +487,62 @@ namespace BALL + { + upper_bound = nstate.f; + state.permutation = nstate.permutation; +- state.permutation.push_back(0); ++ BGL_FORALL_VERTICES_T(v, graph_, UndirectedGraph) // yes, it is only one, but still... ++ { ++ state.permutation.push_back(boost::get(boost::vertex_index, graph_, v)); ++ } + } + } + else + { +- std::map<int, VertexType> index_to_vertex; ++ index_to_vertex_.clear(); + BGL_FORALL_VERTICES_T(v, graph_, UndirectedGraph) + { +- index_to_vertex[boost::get(boost::vertex_index, graph_, v)] = v; ++ index_to_vertex_[boost::get(boost::vertex_index, graph_, v)] = v; + } + + for (typename std::vector<Size>::iterator viter = greedy_solution.first.begin(); + viter != greedy_solution.first.end(); ++viter) + { +- VertexType& vertex = index_to_vertex[*viter]; +- Size degree = boost::out_degree(vertex, graph_); +- +- GRAPH::UndoEliminateOperation<UndirectedGraph> elimination(graph_, vertex); +- +- QuickBBState xstate(nstate); +- xstate.g = std::max(nstate.g, degree); +- xstate.permutation.push_back(boost::get(boost::vertex_index, graph_, vertex)); +- +- BitSet bitset(buildBitset()); +- +- Size lower_bound = L()(graph_); +- xstate.h = lower_bound; +- xstate.f = max(xstate.g, lower_bound); +- +- if (xstate.f >= upper_bound) +- { +- elimination.undo(); +- +- continue; +- } +- +- MapPos entry(visitedSubgraphs.insert(MapEntry(bitset, xstate.f))); +- +- if (entry.second) +- { +- branchAndBound(xstate); +- } +- else if ((entry.first)->second > xstate.f) ++ if (index_to_vertex_.find(*viter) != index_to_vertex_.end()) + { +- entry.first->second = xstate.f; +- branchAndBound(xstate); ++ VertexType& vertex = index_to_vertex_[*viter]; ++ Size degree = boost::out_degree(vertex, graph_); ++ ++ GRAPH::UndoEliminateOperation<UndirectedGraph> elimination = GRAPH::eliminateVertexUndoable(vertex, graph_); ++ ++ QuickBBState xstate(nstate); ++ xstate.g = std::max(nstate.g, degree); ++ xstate.permutation.push_back(*viter); ++ ++ BitSet bitset(buildBitset()); ++ ++ Size lower_bound = L()(graph_); ++ xstate.h = lower_bound; ++ xstate.f = max(xstate.g, lower_bound); ++ ++ if (xstate.f >= upper_bound) ++ { ++ VertexType vertex_replace = elimination.undo(); ++ index_to_vertex_[*viter] = vertex_replace; ++ continue; ++ } ++ ++ MapPos entry(visitedSubgraphs.insert(MapEntry(bitset, xstate.f))); ++ ++ if (entry.second) ++ { ++ branchAndBound(xstate); ++ } ++ else if ((entry.first)->second > xstate.f) ++ { ++ entry.first->second = xstate.f; ++ branchAndBound(xstate); ++ } ++ ++ VertexType vertex_replace = elimination.undo(); ++ index_to_vertex_[*viter] = vertex_replace; + } +- +- elimination.undo(); + } + } + } +@@ -687,7 +722,7 @@ namespace BALL + typename TreeWidth<OriginalGraphType>::TreeDecompositionBag + TreeWidthImplementation<UndirectedGraph>::TreeDecompositionBuilder<OriginalGraphType>::buildRoot_(TreeDecompositionBag child) + { +- TreeDecompositionBag last_vertex; ++ TreeDecompositionBag last_vertex = TreeDecompositionBag(); + + TreeDecompositionContent content = boost::get(boost::vertex_bag_content, *nice_tree_, child); + +diff --git a/source/DATATYPE/GRAPH/treeWidth.C b/source/DATATYPE/GRAPH/treeWidth.C +index 981605d..7485305 100644 +--- a/source/DATATYPE/GRAPH/treeWidth.C ++++ b/source/DATATYPE/GRAPH/treeWidth.C +@@ -1 +1,25 @@ + #include <BALL/DATATYPE/GRAPH/treeWidth.h> ++ ++#include <BALL/KERNEL/atom.h> ++ ++namespace BALL ++{ ++ template <> ++ void TreeWidth<MolecularGraph>::BagContentWriter::operator() (std::ostream& out, const TreeDecompositionBag& v) const ++ { ++ out << "[label=\""; ++ ++ // find all vertices in the current bag ++ TreeDecompositionContent content = boost::get(boost::vertex_bag_content, *td_, v); ++ ++ for (typename TreeDecompositionContent::const_iterator tdc_it = content.begin(); tdc_it != content.end(); ++tdc_it) ++ { ++ TreeWidth<MolecularGraph>::OriginalVertexType ov = *tdc_it; ++ Atom const* atom = boost::get(boost::vertex_atom_ptr, *original_graph_, ov); ++ ++ out << atom->getFullName() << " (" << atom << ") " << "\\n"; ++ } ++ ++ out << "\"]"; ++ } ++} +diff --git a/source/STRUCTURE/BONDORDERS/FPTBondOrderStrategy.C b/source/STRUCTURE/BONDORDERS/FPTBondOrderStrategy.C +index 4f872ae..c708535 100644 +--- a/source/STRUCTURE/BONDORDERS/FPTBondOrderStrategy.C ++++ b/source/STRUCTURE/BONDORDERS/FPTBondOrderStrategy.C +@@ -68,7 +68,7 @@ namespace BALL + for (Position i = 0; i < ntds.size(); ++i) + { + bond_assignments.push_back(new FPTBondOrderAssignment_(*this, ntds[i], upper_bound_)); +- Penalty result = bond_assignments[i]->compute(); ++ bond_assignments[i]->compute(); + } + + // initialize backtracking +@@ -650,8 +650,8 @@ namespace BALL + { + Edge e = *it; + +- MolecularGraphTraits::VertexType source = boost::source(*it, *molecule_); +- MolecularGraphTraits::VertexType target = boost::target(*it, *molecule_); ++ MolecularGraphTraits::VertexType source = boost::source(e, *molecule_); ++ MolecularGraphTraits::VertexType target = boost::target(e, *molecule_); + + if (iv == source || iv == target) + { +@@ -1893,8 +1893,7 @@ namespace BALL + + BGL_FORALL_EDGES(edge_it, graph, MolecularGraph) + { +- if (boost::source(edge_it, graph) < boost::target(edge_it, graph)) +- sorted_edges.push_back(edge_it); ++ sorted_edges.push_back(edge_it); + } + + // sort bonds - the second vertex could be in false order +@@ -1927,8 +1926,7 @@ namespace BALL + + BGL_FORALL_EDGES(edge_it, graph, MolecularGraph) + { +- if (boost::source(edge_it, graph) < boost::target(edge_it, graph)) +- sorted_edges.push_back(edge_it); ++ sorted_edges.push_back(edge_it); + } + + // sort bonds - the second vertex could be in false order |