Пример #1
0
/*
 * lahiri()
 * - implements the NCD-UTVPI() algorithm from An Efficient Decision Procedure for UTVPI Constraints - Lahiri, Musuvathi
 * - calls johnsonAllPairs(), into which the Model Generation algorithm from this paper was integrated, in order to significantly
 *   reduce the space complexity of this implementation
 * - if the system is found to be integrally infeasible, returns a pointer to a ConstraintRefList storing a proof of this
 * - otherwise, returns NULL
 *
 * Gphi - pointer to the overall System struct containing the graph representation
 */
static ConstraintRefList * lahiri(System * Gphi){
  System GphiPrime;
  onlySlacklessEdges(Gphi, &GphiPrime);
  stronglyConnectedComponents(&GphiPrime);
  int infeasibleVertexIndex = -1;
  for(int i = 0; i < Gphi->n && infeasibleVertexIndex < 0; i++){
    if( GphiPrime.graph[POSITIVE][i].sccNumber == GphiPrime.graph[NEGATIVE][i].sccNumber
        && ( Gphi->graph[POSITIVE][i].D - Gphi->graph[NEGATIVE][i].D ) % 2 != 0 ){
      infeasibleVertexIndex = i;
    }
  }
  if( infeasibleVertexIndex >= 0 ){
    ConstraintRefList * infeasibilityProof = generateProof(Gphi, &GphiPrime, infeasibleVertexIndex);
    freeSystem( &GphiPrime );
    return infeasibilityProof;
  }
  freeSystem( &GphiPrime );
  setSystemForJohnson( Gphi );
  johnsonAllPairs( Gphi );
  return NULL;
}
Пример #2
0
const BaseMath &
BaseMath::writeStrongComponents( std::ostream & os ) const {

	typedef InputGraph Graph;
	auto const & g = this->_input_graph;

	Graph::NodeMap< int > component_id(g);
	const int n_components = stronglyConnectedComponents( g, component_id );

	std::vector< int > component_size( n_components, 0 );
	std::vector< int > component_non_dummy_size( n_components, 0 );

	/**
	 * Iterate all nodes, get the component id,
	 * update the size.
	 */
	for ( Graph::NodeIt n(g); n != lemon::INVALID; ++ n ) {
		++ component_size[ component_id[n] ];
		if ( !_dummy[n] ) {
			++ component_non_dummy_size[ component_id[n] ];
		}
	}

	os << "Strongly connected components of input graph = " << n_components << std::endl;
	os << "Component sizes =";
	for ( auto n : component_size ) {
		os << " " << n;
	}
	os << std::endl;

	os << "Component sizes (non-dummy) =";
	for ( auto n : component_non_dummy_size ) {
		os << " " << n;
	}
	os << std::endl;

	return *this;
}