public Document modifyDocumentFrom(InstanceCheckerEngine logic, Document document, InstanceCheckerParser problem) {
		Element functionsElement = XMLManager.getElementByTagNameFrom(document.getDocumentElement(), InstanceTokens.FUNCTIONS, 0);
		if (functionsElement != null)
			document.getDocumentElement().removeChild(functionsElement);

		Element predicatesElement = XMLManager.getElementByTagNameFrom(document.getDocumentElement(), InstanceTokens.PREDICATES, 0);
		if (predicatesElement != null)
			document.getDocumentElement().removeChild(predicatesElement);

		Element constraintsElement = XMLManager.getElementByTagNameFrom(document.getDocumentElement(), InstanceTokens.CONSTRAINTS, 0);
		NodeList nodeList = constraintsElement.getElementsByTagName(InstanceTokens.CONSTRAINT);
		for (int i = 0; i < nodeList.getLength(); i++) {
			Element element = (Element) nodeList.item(i);

			String reference = element.getAttribute(InstanceTokens.REFERENCE);
			if (problem.getFunctionsMap().containsKey(reference) || problem.getPredicatesMap().containsKey(reference)) {
				Element parameters = XMLManager.getElementByTagNameFrom(element, InstanceTokens.PARAMETERS, 0);
				element.removeChild(parameters);
				String name = element.getAttribute(InstanceTokens.NAME);
				element.setAttribute(InstanceTokens.REFERENCE, problem.getConstraintsToNewRelations().get(name));
			}
		}
		Element relationsElement = XMLManager.getElementByTagNameFrom(document.getDocumentElement(), InstanceTokens.RELATIONS, 0);
		if (relationsElement == null) {
			relationsElement = document.createElement(InstanceTokens.RELATIONS);
			document.getDocumentElement().insertBefore(relationsElement, constraintsElement);
		}
		relationsElement.setAttribute(InstanceTokens.NB_RELATIONS, problem.getRelationsMap().size() + problem.getNewRelations().size() + ""); // relations.size() + "");

		// int spotLimit = (problem.getNewRelations().size() / 20);
		int cpt = 0;
		for (PRelation relation : problem.getNewRelations()) {
			cpt++;
			Element relationElement = document.createElement(InstanceTokens.RELATION);
			relationElement.setAttribute(InstanceTokens.NAME, relation.getName());
			relationElement.setAttribute(InstanceTokens.ARITY, relation.getArity() + "");
			relationElement.setAttribute(InstanceTokens.NB_TUPLES, relation.getTuples().length + "");
			relationElement.setAttribute(InstanceTokens.SEMANTICS, relation.getSemantics());
			if (relation instanceof PSoftRelation) 
				relationElement.setAttribute(InstanceTokens.DEFAULT_COST, ((PSoftRelation)relation).getDefaultCost()+ "");
			
			relationElement.setTextContent(relation.getStringListOfTuples());
			relationsElement.appendChild(relationElement);
			if (cpt % 10 == 0)
				logic.spot();
		}
		return document;
	}