// stepBH.c

//	JR
//	4/11/96	To do one user-selected move at a time, 
//	4/20/96 or run Bestvina-Handel.

//#define NDEBUG 1	// This would cause calls to assert to be ignored.

//#include <iostream.h>
#include <iostream>
using namespace std;
#include "Homeo.H"

main()
{
   istream& in=cin;
   Homeo H(in);
   cout << endl << H << endl;

	assert(H.componentsOfPeripheryAreCircles());

	cout << "Fold: f e1 e2 n" << endl;
	cout << "Subdivide: s e1 n" << endl;
	cout << "Absorb: a" << endl;
	cout << "Reducible?: r" << endl;
	cout << "Valence 1: v1" << endl;
	cout << "Valence 2: v2" << endl;
	cout << "Collapse forest: c" << endl;
	cout << "Tighten: t" << endl;
	cout << "Growth rate?: g" << endl;
	cout << "Efficient?: e" << endl;
	cout << "Bestvina-Handel algorithm: b" << endl;
	cout << "Handel-Bestvina algorithm: h" << endl;
	cout << "New homeomorphism: n" << endl;


   while(1)
   {
	// Get command.
	// options are:
	// 	fold e f
	//	divide e n
	//      etc.

	DE e,f;
	int n;
	cout << "Now what?" << endl;
	eatWhiteSpace(in);
	char c;
	in.get(c);
	if(c=='f')
	{
//				 FOLD;
		in >> e >> f >> n;
		if(n==0)
		{
			cout << "New edge is " << H.foldMany(e,f) << endl;
		}
		else
		{
			cout << "New edge is " << H.fold(e,f,n) << endl;
		}

	   	cout << endl << H << endl;
	}
	else if(c=='s')
	{
//				 SUBDIVIDE;
		in >> e >> n;
		cout << "New edge is " << H.subdivideOrigNear(e,n) << endl;
	   	cout << endl << H << endl;
	}
	else if(c=='a')
	{
//				 ABSORB;
		H.absorbIntoP();
	   	cout << endl << H << endl;
	}
	else if(c=='r')
	{
//				 REDUCIBLE;
		if( H.reducible() || H.reducibleType2() ) cout << "Reducible." << endl;
		else 		    cout << "Not reducible." << endl;
	}
	else if(c=='v')
	{
		in.get(c);
		if(c=='1') 
		{
//				VALENCE1;
			H.removeValenceOneVertices();
		}
		else
		{
//				VALENCE2;
			H.removeAValenceTwoVertex();
		}
   		cout << endl << H << endl;
	}
	else if(c=='c')
	{
//				 COLLAPSEFOREST;
		H.collapseInvariantForest();
	   	cout << endl << H << endl;
	}
	else if(c=='t')
	{
//				 TIGHTEN;
		H.pullTight();
	   	cout << endl << H << endl;
	}
	else if(c=='g')
	{
//				 GROWTHRATE;
		double g=H.growthRate(1.0e-7,100);
		cout << "Growth rate is " << g << endl;
	}
	else if(c=='e')
	{
//				 EFFICIENT?;
		Boolean e=H.efficient();
		if(e) cout << "Efficient. " << endl;
		else  cout << "Not efficient. " << endl;
	}
	else if(c=='b' || c=='h')
	{
		int type=H.BH();
	}
	else if(c=='n')
	{
		H=Homeo(in);
		cout << endl << H << endl;
	}
	else exit(0);
   }
}

