public String toStringFile() {
        StringBuilder string = new StringBuilder();

        HashMap<NodeVariable, Integer> nodevariable_agent = new HashMap<NodeVariable, Integer>();
        HashMap<NodeFunction, Integer> nodefunction_agent = new HashMap<NodeFunction, Integer>();

        Iterator<NodeVariable> itnv;
        Iterator<NodeFunction> itnf;
        FunctionEvaluator fe;

        // AGENTS

        Iterator<Agent> ita = this.agents.iterator();
        while (ita.hasNext()) {
            Agent agent = ita.next();
            string.append("AGENT ").append(agent.id()).append("\n");

            itnv = agent.getVariables().iterator();
            while (itnv.hasNext()) {
                NodeVariable nodeVariable = itnv.next();
                nodevariable_agent.put(nodeVariable, agent.id());
            }

            itnf = agent.getFunctions().iterator();
            while (itnf.hasNext()) {
                NodeFunction nodeFunction = itnf.next();
                nodefunction_agent.put(nodeFunction, agent.id());
            }

        }

        // VARIABLES

        itnv = this.factorgraph.getNodevariables().iterator();
        while (itnv.hasNext()) {
            NodeVariable nodeVariable = itnv.next();
            string.append("VARIABLE ").append(nodeVariable.id()).append(" ").append(nodevariable_agent.get(nodeVariable)).append(" ").append(nodeVariable.size()).append("\n");
        }

        // FUNCTIONS

        itnf = this.factorgraph.getNodefunctions().iterator();
        while (itnf.hasNext()) {
            NodeFunction nodeFunction = itnf.next();
            //string.append("CONSTRAINT ").append(nodeFunction.id()).append(" ").append(nodefunction_agent.get(nodeFunction)).append(" ");
            // constraint?!
            string.append(nodeFunction.getTypeOfFe()).append(nodeFunction.id()).append(" ").append(nodefunction_agent.get(nodeFunction)).append(" ");

            // variables id
            fe = nodeFunction.getFunction();
            for (int i = 0; i < fe.parametersNumber(); i++) {
                string.append(fe.getParameter(i).id() + " ");
            }
            string.append("\n");

            // variables values and function cost
            string.append(fe.toStringForFile());

        }




        return string.toString();
    }