Ignore:
Timestamp:
Jul 12, 2017, 7:10:32 PM (8 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Action_Thermostats, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, AutomationFragmentation_failures, Candidate_v1.6.1, ChemicalSpaceEvaluator, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Exclude_Hydrogens_annealWithBondGraph, Fix_Verbose_Codepatterns, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, Gui_displays_atomic_force_velocity, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, PythonUI_with_named_parameters, Recreated_GuiChecks, StoppableMakroAction, TremoloParser_IncreasedPrecision
Children:
4a6ef3
Parents:
966ce7
git-author:
Frederik Heber <frederik.heber@…> (05/19/17 13:13:41)
git-committer:
Frederik Heber <frederik.heber@…> (07/12/17 19:10:32)
Message:

Edges may be added and removed in BoostGraphCreator.

  • TESTS: added unit test case on this.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/Graph/BoostGraphCreator.cpp

    r966ce7 re0b960  
    102102}
    103103
     104BoostGraphCreator::Edge BoostGraphCreator::findEdge(const atomId_t &_firstid, const atomId_t &_secondid)
     105{
     106  edge_iter i, end;
     107  const name_map_t name_map = boost::get(boost::vertex_name, graph);
     108  for (boost::tie(i, end) = boost::edges(graph); i != end; ++i) {
     109    const BoostGraphCreator::Edge &e = *i;
     110    const Vertex u = source(e, graph);
     111    const Vertex v = target(e, graph);
     112    const atomId_t atomid_u = boost::get(name_map, u);
     113    const atomId_t atomid_v = boost::get(name_map, v);
     114    if (atomid_u == _firstid) {
     115      if (atomid_v == _secondid)
     116        break;
     117    } else if (atomid_u == _secondid) {
     118      if (atomid_v == _firstid)
     119        break;
     120    }
     121  }
     122  if (i != end) {
     123    BoostGraphCreator::Edge e = *i;
     124    return e;
     125  }
     126
     127  return BoostGraphCreator::Edge();
     128}
     129
     130bool BoostGraphCreator::removeEdge(const atomId_t &_firstid, const atomId_t &_secondid)
     131{
     132  // look through all edges
     133  BoostGraphCreator::Edge e = findEdge(_firstid, _secondid);
     134
     135  // edge was found
     136  if (e != BoostGraphCreator::Edge()) {
     137    const Vertex u = source(e, graph);
     138    const Vertex v = target(e, graph);
     139    if (DoLog(3)) {
     140      const name_map_t name_map = boost::get(boost::vertex_name, graph);
     141      LOG(3, "DEBUG: Found edge " << boost::get(name_map, u) <<  " <-> "
     142          << boost::get(name_map, v) << ", removing.");
     143    }
     144    boost::remove_edge(e, graph);
     145
     146    return true;
     147  }
     148  return false;
     149}
     150
     151bool BoostGraphCreator::addEdge(const atomId_t &_firstid, const atomId_t &_secondid)
     152{
     153  // look through all edges
     154  BoostGraphCreator::Edge e = findEdge(_firstid, _secondid);
     155
     156  if (e != BoostGraphCreator::Edge()) {
     157    return false;
     158  } else {
     159    const nodeId_t leftnodeid = getNodeId(_firstid);
     160    const nodeId_t rightnodeid = getNodeId(_secondid);
     161
     162    boost::add_edge(leftnodeid, rightnodeid, graph);
     163
     164    return true;
     165  }
     166}
Note: See TracChangeset for help on using the changeset viewer.