//************************************************************************
//************************************************************************
// Creates a random graph and checks if there is a non-greedy step in the
// range given.  If so it returns the sub_graph, otherwise a null.
//************************************************************************
//************************************************************************

#include <LINK/userobj/PostAnalyze.h>


Graph*
Extract(Graph* g, int percent, int flag, Sequence<Vertex*> vs, int deviation)
{
	int g_order, induce_int, cost_diff, noempt = 0;
	int count = 0, placement = 99, temp = deviation;
	double induce_percent;
	Vertex* v;
	Set<Vertex*> ps;

	ps.clear();

	count = 0;

	// need to InitPost, then PostAnalyze(g, steps)
	// where steps is determined from percent
	
	g_order = g->order();
	cout << "In extract  order = " << g_order;
	cout << "  vs.size()  = " <<  vs.size() << endl;
	
	induce_percent = (float)(percent/100.) * g_order;
	cout << "In Extract induce_percent = " << induce_percent << endl;
	
	induce_int = (int)induce_percent + deviation;
	cout << "In Extract induce_int = " << induce_int << endl;
	
	ps = PlacedPartitions(g, UNPLACED);  // changed

	Iterator<Vertex*> traverse(&ps);

	deviation += deviation;

	count = 0;
	while(traverse(v) && flag != placement) // needs work
	{
		count++;
		getAttribute((GraphObject*) v, "greediness", placement);
		if(flag != placement) ps.remove(v);
		else noempt = 1;
	}
	if (!noempt) ps.clear();
		
	Graph* induced_graph = g->inducedSubgraph(ps, CLONE);
		
	if (ps.emptyQ()) return NULL;
	return induced_graph;
}
