Ignore:
Timestamp:
Apr 23, 2021, 8:51:43 PM (5 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.7.0, stable
Children:
9171d8
Parents:
d951a5
git-author:
Frederik Heber <frederik.heber@…> (03/27/21 16:54:08)
git-committer:
Frederik Heber <frederik.heber@…> (04/23/21 20:51:43)
Message:

FIX: Several small errors in Graph6Reader.

  • off-by-one error with encoding starts at 63 (0), not 64.
  • cur_byte needs to exist outside of scope of next_edge().
  • need a mapping from edges_by_vertices in the subgraph (with indices from the subgraph vertices) to the edge index used in th degrees array to properly calculate the bond degrees.
  • TESTS: Added a chemical space evaluator test case with 3 nodes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/GraphAction/ChemicalSpaceEvaluatorAction.cpp

    rd951a5 r1be100  
    142142{
    143143  const BoostGraphCreator::Vertex u = source(e, graph);
    144   const BoostGraphCreator::Vertex v = source(e, graph);
     144  const BoostGraphCreator::Vertex v = target(e, graph);
    145145  return getEdgeByVertices(u,v);
    146146}
     
    204204    for (boost::tie(i, end) = boost::out_edges(v, graph); i != end; ++i) {
    205205      const BoostGraphCreator::Edge &e = *i;
    206       const BoostGraphCreator::Vertex e1 = source(e, graph);
    207       const BoostGraphCreator::Vertex e2 = target(e, graph);
    208       const edge_by_vertices_t edge_by_vertices = getEdgeByVertices(e1,e2);
     206      const edge_by_vertices_t edge_by_vertices = getEdgeVerticesByEdge(e, graph);
    209207      LOG(3, "DEBUG: Current edge is (" << edge_by_vertices << ")");
    210208      const size_t index = getElementFromMap<edge_index_t, edge_by_vertices_t>(
     
    231229      std::pair<BoostGraphCreator::Edge, bool> edge_inserter =
    232230          boost::add_edge(v, h, newgraph.saturated_graph);
     231      ASSERT( edge_inserter.second,
     232          "Failed to insert hydrogen into saturation graph.");
    233233    }
    234234    LOG(2, "DEBUG: Added " << (max_valence - total_valence)
     
    242242BoostGraphCreator::UndirectedGraph extractSubgraph(
    243243    const graph_t &_graph,
    244     const Extractors::nodes_t &nodes)
     244    const Extractors::nodes_t &nodes,
     245    const edge_index_t &_edge_index,
     246    edge_index_t &_subgraph_edge_index)
    245247{
    246248  BoostGraphCreator::UndirectedGraph subgraph;
    247249  const Extractors::index_map_t index_map = boost::get(boost::vertex_index, _graph);
     250  typedef std::map<Extractors::node_t, BoostGraphCreator::Vertex> graph_index_to_subgraph_vertex_t;
     251  graph_index_to_subgraph_vertex_t graph_index_to_subgraph_vertex;
    248252
    249253  // add nodes
    250254  BoostGraphCreator::vertex_iter viter, vend;
    251255  for (boost::tie(viter, vend) = boost::vertices(_graph); viter != vend; ++viter) {
    252     const size_t nodeid = boost::get(index_map, *viter);
     256    const Extractors::node_t nodeid = boost::get(index_map, *viter);
    253257    if (nodes.find(nodeid) != nodes.end()) {
    254       boost::add_vertex(*viter, subgraph);
     258      const BoostGraphCreator::Vertex vnew = boost::add_vertex(*viter, subgraph);
     259      graph_index_to_subgraph_vertex.insert( std::make_pair(nodeid, vnew) );
    255260      LOG(4, "DEBUG: Adding node " << *viter << " to subgraph.");
    256261    }
    257262  }
     263  const Extractors::index_map_t subgraph_index_map = boost::get(boost::vertex_index, subgraph);
    258264
    259265  // add edges
     
    264270      const Extractors::node_t sourceindex = boost::get(index_map, boost::source(*i, _graph));
    265271      const Extractors::node_t targetindex = boost::get(index_map, boost::target(*i, _graph));
     272      // we need to translate the vertex index from graph to subgraph
     273      const Extractors::node_t subsourceindex = boost::get(
     274          subgraph_index_map, graph_index_to_subgraph_vertex[sourceindex]);
     275      const Extractors::node_t subtargetindex = boost::get(
     276          subgraph_index_map, graph_index_to_subgraph_vertex[targetindex]);
    266277      if ((nodes.find(sourceindex) != nodes.end()) && (nodes.find(targetindex) != nodes.end())
    267278          && (sourceindex < targetindex)) {
    268         boost::add_edge(sourceindex, targetindex, subgraph);
    269         LOG(4, "DEBUG: Adding edge " << sourceindex << "<->" << targetindex << " to subgraph.");
     279        // and we need to translate the edge index from the graph to the subgraph
     280        const std::pair<BoostGraphCreator::Edge, bool> newedgeinserter =
     281            boost::add_edge(subsourceindex, subtargetindex, subgraph);
     282        ASSERT( newedgeinserter.second,
     283            "extractSubgraph() - could not insert edge "+toString(subsourceindex)+"<->"
     284            +toString(subtargetindex)+".");
     285        const edge_by_vertices_t edge_by_vertices = getEdgeVerticesByEdge(*i, _graph);
     286        const edge_index_t::const_iterator edgeiter = _edge_index.find(edge_by_vertices);
     287        ASSERT( edgeiter != _edge_index.end(),
     288            "extractSubgraph() - could not find edge "+toString(edge_by_vertices)+" in edge_index map." );
     289        const edge_by_vertices_t subgraph_edge_by_vertices =
     290            getEdgeVerticesByEdge(newedgeinserter.first, subgraph);
     291        _subgraph_edge_index.insert( std::make_pair(subgraph_edge_by_vertices, edgeiter->second) );
     292        LOG(4, "DEBUG: Adding edge " << sourceindex << "<->" << targetindex
     293            << " in graph to subgraph as edge " << subsourceindex << "<->" << subtargetindex << ".");
    270294      }
    271295    }
     
    412436  }
    413437
    414   typedef std::vector<
    415       std::pair<
    416           BoostGraphCreator::UndirectedGraph,
    417           degrees_t> > graphs_with_degrees_t;
    418 
    419438  // 6. for every combination saturate fragments for lookup and energy contribution summation
     439  size_t num_admissible = 0;
    420440  const HomologyContainer &container = World::getInstance().getHomologies();
    421441  for (list_of_edge_degrees_t::const_iterator degrees_iter = list_of_edge_degrees.begin();
     
    436456      continue;
    437457    } else {
     458      ++num_admissible;
    438459      LOG(2, "DEBUG: The degree combination is admissable.");
    439460    }
     
    452473
    453474      // create subgraph
    454       Extractors::UndirectedGraph newgraph = extractSubgraph(graph, current_nodes);
     475      edge_index_t subgraph_edge_index;
     476      Extractors::UndirectedGraph newgraph = extractSubgraph(
     477          graph, current_nodes, edge_index, subgraph_edge_index);
    455478
    456479      const BoostGraphCreator::name_map_t new_name_map =
     
    469492      SaturatedGraph fragmentgraph =
    470493          saturateGraph(newgraph, new_name_map,
    471               type_index_lookup, type_valence_map, edge_index,
     494              type_index_lookup, type_valence_map, subgraph_edge_index,
    472495              edges, current_degrees);
    473496
     
    514537    LOG(1, "The graph with degrees " << current_degrees << " has a total BOSSANOVA energy of " << total_energy);
    515538  }
     539  LOG(1, "There have been " << num_admissible << " admissible degree combinations for the given graph.");
    516540
    517541  return Action::success;
Note: See TracChangeset for help on using the changeset viewer.