#include<stk.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/stkWrapper/Wrapper.h>
#include<LINK/algorithm/Algorithms.h>
#include<LINK/algorithm/Partitioning.h>
#include<LINK/basic/Sequence.h>
#include<LINK/graph/Graph.h>
#include<LINK/graph/Edge.h>
#include<LINK/graph/Vertex.h>

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

static PRIMITIVE KLFMCmd(SCM parms, int len)
{
    SCM graph, view=UNBOUND, problem_type=UNBOUND, iterations=UNBOUND;
    Graph *gr;
    char *name=0;
    Vertex *v;
    int& v_type = Wrapper<Vertex*>::type;

    if (len == 0)
	return UNDEFINED;
    if (len >= 1)
	graph = CAR(parms);
    if (len >= 2)
	problem_type = CAR(CDR(parms));
    if (len >= 3)
	iterations = CAR(CDR(CDR(parms)));

    if (!(gr = getGraph(graph)))
	Err("klfm: bad arg 1, graph expected", graph);
    if ((len > 1) && (!INTEGERP(problem_type)))
	Err("klfm: bad arg 2, integer expected (problem type)", problem_type);
    if ((len > 2) && (!INTEGERP(iterations)))
	Err("klfm: bad arg 3, integer expected (iterations)", iterations);
    int cuts=0;
    int iter = 10;
    int prob_type = MAX_CUT;

    if (INTEGERP(problem_type))
	prob_type = INTEGER(problem_type);
    if (INTEGERP(iterations))
	iter = INTEGER(iterations);

    if (len > 2) {
 	cuts = KLFM(gr,prob_type, iter);
    } else if (len > 1) {
    	cuts = KLFM(gr,prob_type);
    } else 
    	cuts = KLFM(gr);
    return STk_makeinteger(cuts);
}

void gen_KLFM_Wrapper()
{
        STk_add_new_cpp_primitive("klfm", tc_lsubr,
				 (PRIMITIVE (*)(...))KLFMCmd);
        STk_add_new_cpp_primitive("breadth-first-search", tc_lsubr,
				 (PRIMITIVE (*)(...))KLFMCmd);
}
