#include<stk.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/stkWrapper/Wrapper.h>
#include<LINK/algorithm/Algorithms.h>
#include<LINK/graph/Graph.h>
#include<LINK/graph/HyperGraph.h>
#include<LINK/graph/Edge.h>

#include <stdio.h>
#include <stdlib.h>

static PRIMITIVE GoldbergTarjanCmd(SCM parms, int len)
{
	if (len < 1)
                Err("goldberg-tarjan <graph*> <a|b|c>? <A|B>? <Y|?>?",NIL);

        Graph *gr;
	SCM   stk_graph = CAR(parms); // CAR,CDR: see stk.h
	SCM   args = CDR(parms);

        if (!(gr = getGraph(stk_graph))) // getGraph: stkUtils.cc
                Err("goldberg-tarjan: bad arg 1, graph expected", stk_graph);
	char vertexselection = LIFO;
	char relabelchoice   = GLOBAL;
	char labelingchoice  = GLOBAL;
	if (!NULLP(args)) {
		if (!INTEGERP(CAR(args)))
                	Err("goldberg-tarjan: bad arg 2, string or symbol",
							CAR(args));
		vertexselection = INTEGER(CAR(args));
		args = CDR(args);
	}
	if (!NULLP(args)) {
		if (!INTEGERP(CAR(args)))
                	Err("goldberg-tarjan: bad arg 3, string or symbol",
							CAR(args));
		relabelchoice = INTEGER(CAR(args));
		args = CDR(args);
	}
	if (!NULLP(args)) {
		if (!INTEGERP(CAR(args)))
                	Err("goldberg-tarjan: bad arg 4, string or symbol",
							CAR(args));
		labelingchoice = INTEGER(CAR(args));
		args = CDR(args);
	}
        int maxflow = GoldbergTarjan(gr,vertexselection,relabelchoice,
				  labelingchoice);
	return STk_makeinteger(maxflow);
}

void gen_GoldbergTarjan_Wrapper()
{
        STk_add_new_cpp_primitive("goldberg-tarjan", tc_lsubr,
                             (PRIMITIVE (*)(...))GoldbergTarjanCmd);
}
