articulationConditioningSameCount::articulationConditioningSameCount(context const& contextObj, boost::mt19937& randomSource) : ::residualConnectivity::withSub(contextObj, randomSource), weight(1) { nUpVertices = 0; std::size_t nVertices = boost::num_vertices(contextObj.getGraph()); for(std::size_t i = 0; i < nVertices; i++) { if(state[i].state & ON_MASK) nUpVertices++; } }
void conditionArticulation(boost::shared_array<vertexState> state, mpfr_class& weight, const context& contextObj, std::vector<int>& scratch, boost::detail::depth_first_visit_restricted_impl_helper<filteredGraphType>::stackType& filteredGraphStack) { const context::inputGraph& graph = contextObj.getGraph(); filteredGraphType filtered(graph, boost::keep_all(), filterByStateMask(state.get(), UNFIXED_MASK | ON_MASK)); //get out biconnected components of helper graph (which has different vertex ids, remember) std::vector<std::size_t> articulationVertices; boost::articulation_points(filtered, std::back_inserter(articulationVertices)); typedef boost::color_traits<boost::default_color_type> Color; std::vector<boost::default_color_type> colorMap(boost::num_vertices(contextObj.getGraph()), Color::white()); findFixedOnVisitor fixedVisitor(state.get()); const std::vector<mpfr_class> operationalProbabilities = contextObj.getOperationalProbabilities(); for(std::vector<std::size_t>::iterator i = articulationVertices.begin(); i != articulationVertices.end(); i++) { if(state[*i].state != FIXED_ON) { std::fill(colorMap.begin(), colorMap.end(), Color::white()); colorMap[*i] = Color::black(); filteredGraphType::out_edge_iterator current, end; boost::tie(current, end) = boost::out_edges(*i, filtered); int nComponentsWithFixedOnVertices = 0; for(; current != end; current++) { std::size_t otherVertex = current->m_target; if(colorMap[otherVertex] != Color::black()) { fixedVisitor.found = false; boost::detail::depth_first_visit_restricted_impl(filtered, otherVertex, fixedVisitor, &(colorMap[0]), filteredGraphStack, boost::detail::nontruth2()); if(fixedVisitor.found) nComponentsWithFixedOnVertices++; if(nComponentsWithFixedOnVertices > 1) break; } } if(nComponentsWithFixedOnVertices > 1) { state[*i].state = FIXED_ON; weight *= operationalProbabilities[*i]; } } } }
void withSub::getSubObservation(int radius, vertexState* newState, const context& contextObj, const vertexState* oldStatesPtr) { std::size_t nVertices = boost::num_vertices(contextObj.getGraph()); const int* shortestDistances = contextObj.getShortestDistances(); std::size_t sourceVertex = 0; std::fill(newState, newState+nVertices, vertexState::fixed_off()); while(sourceVertex < nVertices) { //is this vertex marked as on, for one reason or another? If so continue from here if((oldStatesPtr[sourceVertex].state & ON_MASK) > 0 && newState[sourceVertex].state == FIXED_OFF) { newState[sourceVertex].state = FIXED_ON; //Do we find another vertex in our search that is marked on, and is far enough away from the source? //If so retain it, it will be our new starting point. //If no such found, we'll continue from finalSearchVertex+1 bool found = false; std::size_t nextSourceVertex = -1; //keep copy of source vertex std::size_t copiedSourceVertex = sourceVertex; //we want to begin on the NEXT vertex sourceVertex++; while(sourceVertex < nVertices) { int previousState = oldStatesPtr[sourceVertex].state; if(shortestDistances[copiedSourceVertex + nVertices * sourceVertex] <= radius) { if(previousState & FIXED_MASK) newState[sourceVertex].state = previousState; else newState[sourceVertex].state = UNFIXED_OFF; } else if(!found && (previousState & ON_MASK) > 0 && newState[sourceVertex].state == FIXED_OFF) { nextSourceVertex = sourceVertex; found = true; } sourceVertex++; } //if we found another vertex, continue from there. If no, we're already at finalSearchVertex+1. //Which is where we want to be. if(found) { sourceVertex = nextSourceVertex; } } else sourceVertex++; } }
articulationConditioningImportance::articulationConditioningImportance(context const& contextObj, boost::mt19937& randomSource, const std::vector<double>* importanceProbabilities) : ::residualConnectivity::withSub(contextObj), weight(1), importanceProbabilities(importanceProbabilities) { std::size_t nVertices = boost::num_vertices(contextObj.getGraph()); boost::shared_array<vertexState> state(new vertexState[nVertices]); for(std::size_t i = 0; i < nVertices; i++) { boost::random::bernoulli_distribution<double> vertexDistribution((*importanceProbabilities)[i]); if(vertexDistribution(randomSource)) { state[i].state = UNFIXED_ON; } else { state[i].state = UNFIXED_OFF; } } this->state = state; }
basic::basic(context const& contextObj, boost::shared_array<const vertexState> state, int radius, ::residualConnectivity::subObs::basicConstructorType& otherData) : ::residualConnectivity::subObs::subObsWithRadius(contextObj, state, radius) { potentiallyConnected = isSingleComponentPossible(contextObj.getGraph(), state.get(), otherData.components, otherData.stack); }