#include<iostream.h>
#include "ProgFlowInfo.h"
#include <LINK/graph/Edge.h>
#include <LINK/graph/Attribute.h>
int FlowInfo::flow(Edge *e) const
{
	int f;
	if (e->owner() != _g) {
	    error("FlowInfo::flow(): illegal edge"); return 0;
	}
	if (getAttribute((GraphObject*)e,"flowvalue",f) == LINK_GET_ATTR_FAIL) {
	    error("FlowInfo::flow(): no flowvalue attribute set"); return 0;
	}
	return f;
}
int FlowInfo::capacity(Edge *e) const
{
	int c;
	if (e->owner() != _g) {
	    error("FlowInfo::flow(): illegal edge"); return 0;
	}
	if (getAttribute((GraphObject*)e,"capacity",c) == LINK_GET_ATTR_FAIL) {
	    error("FlowInfo::flow(): no capacity attribute set"); return 0;
	}
	return c;
}
ostream& operator<<(ostream &, Container<Vertex *> const &);

ostream& operator<<(ostream& os, const FlowInfo& finfo)
{
	int i;
	os << "{" << finfo._g->vertices();
	Iterator<Edge*> get_edge(&finfo._g->edges());
	Edge *e;
	while (get_edge(e)) {
		os << "{" << *e;
		os << "(" << finfo.flow(e) << "," << finfo.capacity(e) << ")";
		os << "}";
	}
}
void FlowInfo::display() const
{
	cout << *this;
}
