Author: chatellier Date: 2011-05-20 15:29:55 +0000 (Fri, 20 May 2011) New Revision: 3334 Log: Gestion des types de facteur min/max et pourcentage pour l'import/export xml. Added: isis-fish/branches/3.3.1/src/test/resources/mexico/mexicohelper_designplanV2.xml Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/ContinuousDomainXMLVisitor.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/DesignPlanXMLVisitor.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/DomXMLParser.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/EquationContinuousDomainXMLVisitor.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/FactorXMLVisitor.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/MatrixContinuousDomainXMLVisitor.java isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/mexico/MexicoHelperTest.java Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/ContinuousDomainXMLVisitor.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/ContinuousDomainXMLVisitor.java 2011-05-19 15:30:08 UTC (rev 3333) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/ContinuousDomainXMLVisitor.java 2011-05-20 15:29:55 UTC (rev 3334) @@ -50,14 +50,28 @@ ContinuousDomain cDomain = (ContinuousDomain)domain; xmlBuffer.append(" cardinality=\"" + cDomain.getCardinality() + "\">"); + appendDomain(cDomain); + } + + /** + * Default ContinuousDomain implementation for double. + * Maybe overridden by specific continuous domains. + * + * @param domain domain to print + */ + protected void appendDomain(ContinuousDomain domain) { // facteur continue pourcentage - if (cDomain.getCoefficient() != null || cDomain.getReferenceValue() != null) { - xmlBuffer.append("<percentage coefficient=\"" + cDomain.getCoefficient() + "\""); - xmlBuffer.append(" reference=\"" + cDomain.getReferenceValue() + "\" />"); + if (domain.getCoefficient() != null || domain.getReferenceValue() != null) { + xmlBuffer.append("<reference coefficient=\"" + domain.getCoefficient() + "\">"); + xmlBuffer.append(domain.getReferenceValue()); + xmlBuffer.append("</reference>"); } else { // facteur continue min/max - xmlBuffer.append("<range min=\"" + cDomain.getMinBound() + "\" max=\"" + cDomain.getMaxBound() + "\" />"); + xmlBuffer.append("<range>"); + xmlBuffer.append("<min>" + domain.getMinBound() + "</min>"); + xmlBuffer.append("<max>" + domain.getMaxBound() + "</max>"); + xmlBuffer.append("</range>"); } } Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/DesignPlanXMLVisitor.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/DesignPlanXMLVisitor.java 2011-05-19 15:30:08 UTC (rev 3333) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/DesignPlanXMLVisitor.java 2011-05-20 15:29:55 UTC (rev 3334) @@ -42,10 +42,15 @@ /** * {@inheritDoc} + * + * Changes : + * v2 : depuis la v2, meilleur gestion des min/max, pourcentage poru quasiment + * tous les facteurs continue + * v0 : version original */ @Override public void start(DesignPlan designPlan) { - xmlBuffer.append("<experimentalDesign>"); + xmlBuffer.append("<experimentalDesign version=\"2\">"); } /** Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/DomXMLParser.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/DomXMLParser.java 2011-05-19 15:30:08 UTC (rev 3333) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/DomXMLParser.java 2011-05-20 15:29:55 UTC (rev 3334) @@ -66,10 +66,18 @@ DesignPlan plan = new DesignPlan(); + // could return "2" or null + String version = rootElement.attributeValue("version"); + List<Element> factorGroupElements = rootElement.selectNodes("child::factors"); FactorGroup factorGroup = null; if (!factorGroupElements.isEmpty()) { - factorGroup = parseFactorGroup(factorGroupElements.get(0), topiaContext); + if ("2".equals(version)) { + factorGroup = parseFactorGroupV2(factorGroupElements.get(0), topiaContext); + } + else { + factorGroup = parseFactorGroup(factorGroupElements.get(0), topiaContext); + } } plan.setFactorGroup(factorGroup); @@ -85,7 +93,12 @@ * @return factor group * * @see FactorGroup#isMixed() + * + * @deprecated since 3.4.0.0, this parsing method parse experimentalDesign + * in version "0" or "null" version, don't remove for + * data reading purpose, but could be removed in a future version */ + @Deprecated protected static FactorGroup parseFactorGroup(Element fgElement, TopiaContext topiaContext) { String factorGroupName = fgElement.attributeValue("name"); @@ -266,105 +279,235 @@ return factorGroup; } - - /* - * Parse element root node as Sensitivity Scenarios. + + /** + * Recursive parse of factor group elements (>factors<). * - * @return a {@link SensitivityScenarios} + * This version handle xml file with min/max and percentage factor + * in each continuous factors. * - * TODO : non finished and untested - * - public static SensitivityScenarios parseSensitivityScenarios( - Element rootElement) { + * @param fgElement factor group element (>factors<) + * @param topiaContext context + * @param mixed {@code true} if create factor group need to be mixed + * @return factor group + * + * @see FactorGroup#isMixed() + */ + protected static FactorGroup parseFactorGroupV2(Element fgElement, TopiaContext topiaContext) { - SensitivityScenarios scenarios = new SensitivityScenarios(); + String factorGroupName = fgElement.attributeValue("name"); + FactorGroup factorGroup = new FactorGroup(factorGroupName); - List<Element> scenarioElements = rootElement - .selectNodes("child::scenarios/scenario"); + // sub factor group + List<Element> factorGroupElements = fgElement.selectNodes("child::factors"); + for (Element factorGroupElement : factorGroupElements) { + FactorGroup subFactorGroup = parseFactorGroupV2(factorGroupElement, topiaContext); + factorGroup.addFactor(subFactorGroup); + } + + // normal factors + List<Element> factorElements = fgElement.selectNodes("child::factor"); - for (Element scenarioElement : scenarioElements) { + for (Element factorElement : factorElements) { + String type = factorElement.attributeValue("type"); + String name = factorElement.attributeValue("name"); + String property = factorElement.attributeValue("property"); + String path = factorElement.element("target").getText().trim(); - Scenario scenario = new Scenario(); - List<Element> factorElements = scenarioElement.elements("factor"); + // double + if ("real".equals(type)) { + Factor factor = new Factor(name); + factor.setPath(path); + Element fixedElement = factorElement.element("domain").element("fixed"); + // tous les domaines continues + if (property.endsWith("continuous")) { - for (Element factorElement : factorElements) { - String type = factorElement.attributeValue("type"); - String name = factorElement.attributeValue("name"); - String property = factorElement.attributeValue("property"); - String path = factorElement.element("target").getText().trim(); + ContinuousDomain domain; + if(property.equals("matrixcontinuous")) { + + MatrixContinuousDomain mdomain = new MatrixContinuousDomain(); + Element referenceElement = fixedElement.element("reference"); + if (referenceElement != null) { + // matrix specific + // <coefficient operator="-" value="0.799"/> + mdomain.setCoefficient(Double.valueOf(referenceElement.attributeValue("coefficient"))); + // <mx name="test1" step="0">... + Element matrixElement = referenceElement.element("mx"); + MatrixND matrix = MexicoHelper.getMatrixFromXml(matrixElement, topiaContext); + mdomain.setMatrix(matrix); + } + else { + Element rangeElement = fixedElement.element("range"); + Element minElement = rangeElement.element("min"); + Element maxElement = rangeElement.element("max"); + MatrixND minMatrix = MexicoHelper.getMatrixFromXml(minElement.element("mx"), topiaContext); + MatrixND maxMatrix = MexicoHelper.getMatrixFromXml(maxElement.element("mx"), topiaContext); + mdomain.setMinBound(minMatrix); + mdomain.setMaxBound(maxMatrix); + } - // double - if ("real".equals(type)) { - Factor<Double> factor = new Factor<Double>(name); - factor.setPath(path); - factor.setValue(Double.valueOf(factorElement.element( - "value").getText().trim())); + domain = mdomain; + } + else if (property.equals("equationcontinuous")) { + // equation specific + EquationContinuousDomain edomain = new EquationContinuousDomain(); + edomain.setVariableName(fixedElement.attributeValue("variable")); + Element referenceElement = fixedElement.element("reference"); + if (referenceElement != null) { + edomain.setCoefficient(Double.valueOf(referenceElement.attributeValue("coefficient"))); + edomain.setReferenceValue(Double.valueOf(referenceElement.getTextTrim())); + } + else { + Element rangeElement = fixedElement.element("range"); + Element minElement = rangeElement.element("min"); + Element maxElement = rangeElement.element("max"); + edomain.setMinBound(Double.valueOf(minElement.getTextTrim())); + edomain.setMaxBound(Double.valueOf(maxElement.getTextTrim())); + } - Element fixedElement = factorElement.element("domain") - .element("fixed"); - if ("continuous".equals(property)) { - ContinuousDomain domain = new ContinuousDomain(); - domain.setCardinality(Integer.valueOf(fixedElement - .attributeValue("cardinality"))); - Element rangeElement = fixedElement.element("range"); - domain.setMinBound(Double.valueOf(rangeElement - .attributeValue("min"))); - domain.setMaxBound(Double.valueOf(rangeElement - .attributeValue("max"))); - factor.setDomain(domain); - } else if ("discrete".equals(property)) { - DiscreteDomain domain = new DiscreteDomain(); - List<Element> valueElements = fixedElement.element( - "enumeration").elements("value"); - int label = 0; - for (Element valueElement : valueElements) { - domain.getValues().put( - Integer.valueOf(label), - Double.valueOf(valueElement.getText() - .trim())); - ++label; + domain = edomain; + } + else { + // continous domain + domain = new ContinuousDomain(); + + Element referenceElement = fixedElement.element("reference"); + if (referenceElement != null) { + domain.setCoefficient(Double.valueOf(referenceElement.attributeValue("coefficient"))); + domain.setReferenceValue(Double.valueOf(referenceElement.getTextTrim())); } - factor.setDomain(domain); + else { + // <range max="1.0" min="0.0"/> + Element rangeElement = fixedElement.element("range"); + Element minElement = rangeElement.element("min"); + Element maxElement = rangeElement.element("max"); + domain.setMinBound(Double.valueOf(minElement.getTextTrim())); + domain.setMaxBound(Double.valueOf(maxElement.getTextTrim())); + } } - scenario.getFactors().add(factor); - } else if ("integer".equals(type)) { - Factor factor = new Factor(name); - factor.setPath(path); - factor.setValue(Integer.valueOf(factorElement.element( - "value").getText().trim())); - Element fixedElement = factorElement.element("domain") - .element("fixed"); - if ("continuous".equals(property)) { - ContinuousDomain domain = new ContinuousDomain(); - domain.setCardinality(Integer.valueOf(fixedElement - .attributeValue("cardinality"))); - Element rangeElement = fixedElement.element("range"); - domain.setMinBound(Integer.valueOf(rangeElement - .attributeValue("min"))); - domain.setMaxBound(Integer.valueOf(rangeElement - .attributeValue("max"))); - factor.setDomain(domain); - } else if ("discrete".equals(property)) { - DiscreteDomain domain = new DiscreteDomain(); - List<Element> valueElements = fixedElement.element( - "enumeration").elements("value"); - int label = 0; - for (Element valueElement : valueElements) { - domain.getValues().put( - Integer.valueOf(label), - Integer.valueOf(valueElement.getText() - .trim())); - ++label; + domain.setCardinality(Integer.valueOf(fixedElement.attributeValue("cardinality"))); + + factor.setDomain(domain); + } else if ("discrete".equals(property)) { + DiscreteDomain domain = new DiscreteDomain(); + List<Element> valueElements = fixedElement.element( + "enumeration").elements("value"); + int label = 0; + for (Element valueElement : valueElements) { + domain.getValues().put(Integer.valueOf(label), + Double.valueOf(valueElement.getTextTrim())); + ++label; + } + factor.setDomain(domain); + } + factorGroup.addFactor(factor); + } else if ("integer".equals(type)) { + Factor factor = new Factor(name); + factor.setPath(path); + Element fixedElement = factorElement.element("domain").element("fixed"); + if ("continuous".equals(property)) { + ContinuousDomain domain = null; + + if(property.equals("matrixcontinuous")) { + + MatrixContinuousDomain mdomain = new MatrixContinuousDomain(); + Element referenceElement = fixedElement.element("reference"); + if (referenceElement != null) { + // matrix specific + // <coefficient operator="-" value="0.799"/> + mdomain.setCoefficient(Double.valueOf(referenceElement.attributeValue("coefficient"))); + // <mx name="test1" step="0">... + Element matrixElement = referenceElement.element("mx"); + MatrixND matrix = MexicoHelper.getMatrixFromXml(matrixElement, topiaContext); + mdomain.setMatrix(matrix); } - factor.setDomain(domain); + else { + Element rangeElement = fixedElement.element("range"); + Element minElement = rangeElement.element("min"); + Element maxElement = rangeElement.element("max"); + MatrixND minMatrix = MexicoHelper.getMatrixFromXml(minElement.element("mx"), topiaContext); + MatrixND maxMatrix = MexicoHelper.getMatrixFromXml(maxElement.element("mx"), topiaContext); + mdomain.setMinBound(minMatrix); + mdomain.setMaxBound(maxMatrix); + } + + domain = mdomain; } - scenario.getFactors().add(factor); + else if (property.equals("equationcontinuous")) { + // equation specific + EquationContinuousDomain edomain = new EquationContinuousDomain(); + edomain.setVariableName(fixedElement.attributeValue("variable")); + Element referenceElement = fixedElement.element("reference"); + if (referenceElement != null) { + edomain.setCoefficient(Double.valueOf(referenceElement.attributeValue("coefficient"))); + edomain.setReferenceValue(Double.valueOf(referenceElement.getTextTrim())); + } + else { + Element rangeElement = fixedElement.element("range"); + Element minElement = rangeElement.element("min"); + Element maxElement = rangeElement.element("max"); + edomain.setMinBound(Double.valueOf(minElement.getTextTrim())); + edomain.setMaxBound(Double.valueOf(maxElement.getTextTrim())); + } + + domain = edomain; + } + else { + // continous domain + domain = new ContinuousDomain(); + + Element referenceElement = fixedElement.element("reference"); + if (referenceElement != null) { + domain.setCoefficient(Double.valueOf(referenceElement.attributeValue("coefficient"))); + domain.setReferenceValue(Double.valueOf(referenceElement.getTextTrim())); + } + else { + // <range max="1.0" min="0.0"/> + Element rangeElement = fixedElement.element("range"); + Element minElement = rangeElement.element("min"); + Element maxElement = rangeElement.element("max"); + domain.setMinBound(Integer.valueOf(minElement.getTextTrim())); + domain.setMaxBound(Integer.valueOf(maxElement.getTextTrim())); + } + } + + domain.setCardinality(Integer.valueOf(fixedElement.attributeValue("cardinality"))); + + factor.setDomain(domain); + } else if ("discrete".equals(property)) { + DiscreteDomain domain = new DiscreteDomain(); + List<Element> valueElements = fixedElement.element( + "enumeration").elements("value"); + int label = 0; + for (Element valueElement : valueElements) { + domain.getValues().put(Integer.valueOf(label), + Integer.valueOf(valueElement.getTextTrim())); + ++label; + } + factor.setDomain(domain); } + factorGroup.addFactor(factor); + } else if ("rule".equals(type)) { + Factor factor = new Factor(name); + factor.setPath(path); + Element fixedElement = factorElement.element("domain").element("fixed"); + if ("discrete".equals(property)) { + RuleDomain domain = new RuleDomain(); + List<Element> valueElements = fixedElement.element("enumeration").elements("value"); + int label = 0; + for (Element valueElement : valueElements) { + Element rulesElement = valueElement.element("rules"); + List<Rule> rulesValue = MexicoHelper.getRulesFromXml(rulesElement, topiaContext); + domain.getValues().put(Integer.valueOf(label), rulesValue); + ++label; + } + factor.setDomain(domain); + } + factorGroup.addFactor(factor); } - scenarios.getScenarios().add(scenario); } - return scenarios; - }*/ + return factorGroup; + } } Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/EquationContinuousDomainXMLVisitor.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/EquationContinuousDomainXMLVisitor.java 2011-05-19 15:30:08 UTC (rev 3333) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/EquationContinuousDomainXMLVisitor.java 2011-05-20 15:29:55 UTC (rev 3334) @@ -26,6 +26,7 @@ package fr.ifremer.isisfish.mexico.xml; import fr.ifremer.isisfish.simulator.sensitivity.Domain; +import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain; /** @@ -44,12 +45,36 @@ */ @Override public void start(Domain domain) { - super.start(domain); + xmlBuffer.append("<domain>"); + xmlBuffer.append("<fixed"); EquationContinuousDomain eDomain = (EquationContinuousDomain)domain; - // since 3.3.0.0 coefficient element is outside equation element - xmlBuffer.append("<coefficient value=\"" + eDomain.getCoefficient() + "\" />"); - xmlBuffer.append("<equation variable=\"" + eDomain.getVariableName()+ "\""); - xmlBuffer.append(" reference=\"" + eDomain.getReferenceValue() + "\" />"); + // this version add variable name + xmlBuffer.append(" cardinality=\"" + eDomain.getCardinality() + "\" variable=\"" + eDomain.getVariableName()+ "\">"); + + appendDomain(eDomain); } + + /** + * {@inheritDoc} + */ + @Override + protected void appendDomain(ContinuousDomain domain) { + + EquationContinuousDomain eDomain = (EquationContinuousDomain)domain; + + // facteur continue pourcentage + if (domain.getCoefficient() != null || domain.getReferenceValue() != null) { + xmlBuffer.append("<reference coefficient=\"" + eDomain.getCoefficient() + "\">"); + xmlBuffer.append(eDomain.getReferenceValue()); + xmlBuffer.append("</reference>"); + } + else { + // facteur continue min/max + xmlBuffer.append("<range>"); + xmlBuffer.append("<min>" + domain.getOriginalMinBound() + "</min>"); + xmlBuffer.append("<max>" + domain.getOriginalMaxBound() + "</max>"); + xmlBuffer.append("</range>"); + } + } } Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/FactorXMLVisitor.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/FactorXMLVisitor.java 2011-05-19 15:30:08 UTC (rev 3333) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/FactorXMLVisitor.java 2011-05-20 15:29:55 UTC (rev 3334) @@ -27,6 +27,8 @@ import java.io.Serializable; +import org.nuiton.math.matrix.MatrixND; + import fr.ifremer.isisfish.rule.Rule; import fr.ifremer.isisfish.simulator.sensitivity.Domain; import fr.ifremer.isisfish.simulator.sensitivity.Factor; @@ -59,15 +61,24 @@ // property attribute if (factor.getDomain() instanceof MatrixContinuousDomain) { xmlBuffer.append(" property=\"matrixcontinuous\""); - referenceValueForType = ((MatrixContinuousDomain)factor.getDomain()).getMinBound(); + referenceValueForType = ((ContinuousDomain)factor.getDomain()).getReferenceValue(); + if (referenceValueForType == null) { + referenceValueForType = ((ContinuousDomain)factor.getDomain()).getOriginalMinBound(); + } } else if (factor.getDomain() instanceof EquationContinuousDomain) { xmlBuffer.append(" property=\"equationcontinuous\""); - referenceValueForType = ((ContinuousDomain)factor.getDomain()).getMinBound(); + referenceValueForType = ((ContinuousDomain)factor.getDomain()).getReferenceValue(); + if (referenceValueForType == null) { + referenceValueForType = ((ContinuousDomain)factor.getDomain()).getOriginalMinBound(); + } } else if (factor.getDomain() instanceof ContinuousDomain) { xmlBuffer.append(" property=\"continuous\""); - referenceValueForType = ((ContinuousDomain)factor.getDomain()).getMinBound(); + referenceValueForType = ((ContinuousDomain)factor.getDomain()).getReferenceValue(); + if (referenceValueForType == null) { + referenceValueForType = ((ContinuousDomain)factor.getDomain()).getOriginalMinBound(); + } } else if (factor.getDomain() instanceof DiscreteDomain) { xmlBuffer.append(" property=\"discrete\""); @@ -75,7 +86,8 @@ referenceValueForType = ((DiscreteDomain)factor.getDomain()).getValues().get(firstKey); } // type attribute - if (referenceValueForType instanceof Double || referenceValueForType instanceof Float) { + if (referenceValueForType instanceof Double || referenceValueForType instanceof Float + || referenceValueForType instanceof MatrixND) { xmlBuffer.append(" type=\"real\""); } else if (referenceValueForType instanceof Integer) { Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/MatrixContinuousDomainXMLVisitor.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/MatrixContinuousDomainXMLVisitor.java 2011-05-19 15:30:08 UTC (rev 3333) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/mexico/xml/MatrixContinuousDomainXMLVisitor.java 2011-05-20 15:29:55 UTC (rev 3334) @@ -25,8 +25,10 @@ package fr.ifremer.isisfish.mexico.xml; +import org.nuiton.math.matrix.MatrixND; + import fr.ifremer.isisfish.mexico.MexicoHelper; -import fr.ifremer.isisfish.simulator.sensitivity.Domain; +import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain; /** @@ -44,12 +46,22 @@ * {@inheritDoc} */ @Override - public void start(Domain domain) { - super.start(domain); + protected void appendDomain(ContinuousDomain domain) { MatrixContinuousDomain mDomain = (MatrixContinuousDomain)domain; - // since 3.3.0.0 coefficient element is outside matrix element - xmlBuffer.append("<coefficient value=\"" + mDomain.getCoefficient() + "\" />"); - xmlBuffer.append(MexicoHelper.getMatrixAsXML(mDomain.getMatrix())); + + // facteur continue pourcentage + if (domain.getCoefficient() != null || domain.getReferenceValue() != null) { + xmlBuffer.append("<reference coefficient=\"" + mDomain.getCoefficient() + "\">"); + xmlBuffer.append(MexicoHelper.getMatrixAsXML(mDomain.getMatrix())); + xmlBuffer.append("</reference>"); + } + else { + // facteur continue min/max + xmlBuffer.append("<range>"); + xmlBuffer.append("<min>" + MexicoHelper.getMatrixAsXML((MatrixND)mDomain.getOriginalMaxBound()) + "</min>"); + xmlBuffer.append("<max>" + MexicoHelper.getMatrixAsXML((MatrixND)mDomain.getOriginalMaxBound()) + "</max>"); + xmlBuffer.append("</range>"); + } } } Modified: isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/mexico/MexicoHelperTest.java =================================================================== --- isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/mexico/MexicoHelperTest.java 2011-05-19 15:30:08 UTC (rev 3333) +++ isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/mexico/MexicoHelperTest.java 2011-05-20 15:29:55 UTC (rev 3334) @@ -33,12 +33,14 @@ import java.util.SortedMap; import java.util.TreeMap; +import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.nuiton.math.matrix.MatrixFactory; +import org.nuiton.math.matrix.MatrixHelper; import org.nuiton.math.matrix.MatrixND; import org.nuiton.topia.TopiaContext; @@ -222,18 +224,20 @@ String xml = MexicoHelper.getDesignPlanAsXML(testDesignPlan); // factor 1 - Assert.assertTrue(xml.indexOf("<range min=\"0.0\" max=\"50.0\"/>") != -1); + Assert.assertTrue(xml.contains("<min>0.0</min>")); + Assert.assertTrue(xml.contains("<max>50.0</max>")); // factor 2 - Assert.assertTrue(xml.indexOf("<factor name=\"factor 2 (double discrete)\"") != -1); - Assert.assertTrue(xml.indexOf("<value>70.9</value>") != -1); + Assert.assertTrue(xml.contains("<factor name=\"factor 2 (double discrete)\"")); + Assert.assertTrue(xml.contains("<value>70.9</value>")); // factor 3 - Assert.assertTrue(xml.indexOf("<value>14</value>") != -1); + Assert.assertTrue(xml.contains("<value>14</value>")); // factor 4 - Assert.assertTrue(xml.indexOf("<d>-14.0</d>") != -1); - Assert.assertTrue(xml.indexOf("0.799") != -1); - Assert.assertTrue(xml.indexOf("<mx name=\"test1\">") != -1); + Assert.assertTrue(xml.contains("<d>-14.0</d>")); + Assert.assertTrue(xml.contains("0.799")); + Assert.assertTrue(xml.contains("<mx name=\"test1\">")); // factor 5 - Assert.assertTrue(xml.indexOf("variable=\"L1\" reference=\"45.0\"") != -1); + Assert.assertTrue(xml.contains("<fixed cardinality=\"0\" variable=\"L1\">")); + Assert.assertTrue(xml.contains("<reference coefficient=\"0.1\">45.0</reference>")); if (log.isDebugEnabled()) { log.debug("testGetDesignPlanAsXML xml = " + xml); @@ -352,4 +356,91 @@ } Assert.assertEquals(xml1, xml2); } + + /** + * Test l'ajout des nouveaux type de facteurs, min/max et pourcentage. + * + * @throws IOException + * @throws IsisFishException + */ + @Test + public void testPercentageMinMaxFactor() throws IOException, IsisFishException { + + // get test plan and add some STRANGES factors + DesignPlan testDesignPlan = getTestDesignPlan(false); + + // matrix 1 + MatrixND matrix1 = MatrixFactory.getInstance().create("test1", + new int[] { 3, 2 }, new String[] { "col1", "col2" }); + matrix1 = MatrixHelper.convertToId(matrix1); + + // factor x1 + Factor factorContinuous = new Factor("factor x1"); + ContinuousDomain domain1 = new ContinuousDomain(); + domain1.setReferenceValue(42.0); + domain1.setCoefficient(0.05); + factorContinuous.setDomain(domain1); + factorContinuous.setPath("fr.ifremer.isisfish.entities.PopulationGroup#1156461521013#0.1715620681984218#maxLength"); + + // factor x4 + Factor factorMatrixContinuous = new Factor("factor x4"); + MatrixContinuousDomain domain4 = new MatrixContinuousDomain(); + domain4.setMinBound(matrix1); + domain4.setMaxBound(matrix1); + factorMatrixContinuous.setDomain(domain4); + factorMatrixContinuous.setPath("fr.ifremer.isisfish.entities.PopulationGroup#1156461521076#0.6526656643346673#minLength"); + + // factor x5 + Factor factorEquationContinuous = new Factor("factor x5"); + EquationContinuousDomain domain5 = new EquationContinuousDomain(); + domain5.setMinBound(40.0); + domain5.setMaxBound(50.0); + domain5.setVariableName("Lx1"); + factorEquationContinuous.setDomain(domain5); + factorEquationContinuous.setPath("fr.ifremer.isisfish.entities.PopulationGroup#1156461521076#0.6526656643346673#maxLength"); + + testDesignPlan.addFactor(factorContinuous); + testDesignPlan.addFactor(factorMatrixContinuous); + testDesignPlan.addFactor(factorEquationContinuous); + + // test write + String content = MexicoHelper.getDesignPlanAsXML(testDesignPlan); + File tempFile = File.createTempFile("testdesignplan", ".xml"); + tempFile.deleteOnExit(); + FileUtils.writeStringToFile(tempFile, content); + + // test to read it and get content + DesignPlan plan = MexicoHelper.getDesignPlanFromXML(tempFile, null); + String reReadContent = MexicoHelper.getDesignPlanAsXML(plan); + + Assert.assertEquals(content, reReadContent); + } + + /** + * Test que l'export XML de l'import XML produise le meme xml. + * Pareil, mais pour une version v2 du schema xml. + * + * @throws IOException + * @throws IsisFishException + */ + @Test + public void testExportImportV2() throws IOException, IsisFishException { + + // first export + DesignPlan testDesignPlan = getTestDesignPlan(false); + String xml1 = MexicoHelper.getDesignPlanAsXML(testDesignPlan); + if (log.isDebugEnabled()) { + log.debug("xml 1 = " + xml1); + } + + // export + File testFile = new File("src/test/resources/mexico/mexicohelper_designplanV2.xml"); + // topia context can be null in tests + DesignPlan plan = MexicoHelper.getDesignPlanFromXML(testFile, regionContext); + String xml2 = MexicoHelper.getDesignPlanAsXML(plan); + if (log.isDebugEnabled()) { + log.debug("xml 2 = " + xml2); + } + Assert.assertEquals(xml1, xml2); + } } Added: isis-fish/branches/3.3.1/src/test/resources/mexico/mexicohelper_designplanV2.xml =================================================================== --- isis-fish/branches/3.3.1/src/test/resources/mexico/mexicohelper_designplanV2.xml (rev 0) +++ isis-fish/branches/3.3.1/src/test/resources/mexico/mexicohelper_designplanV2.xml 2011-05-20 15:29:55 UTC (rev 3334) @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8"?> +<experimentalDesign version="2"> + <factors> + <factor name="factor 1 (double continuous)" property="continuous" type="real"> + <target>fr.ifremer.isisfish.entities.PopulationGroup#1156461521013#0.1715620681984218#maxLength</target> + <domain> + <fixed cardinality="0"> + <range> + <min>0.0</min> + <max>50.0</max> + </range> + </fixed> + </domain> + </factor> + <factor name="factor 2 (double discrete)" property="discrete" type="real"> + <target>fr.ifremer.isisfish.entities.PopulationGroup#1156461521064#0.022976136053553198#minLength</target> + <domain> + <fixed cardinality="5"> + <enumeration> + <value>12.3</value> + <value>70.9</value> + <value>21.0</value> + <value>-12.1</value> + <value>-8.45</value> + </enumeration> + </fixed> + </domain> + </factor> + <factor name="factor 3 (integer discrete)" property="discrete" type="integer"> + <target>fr.ifremer.isisfish.entities.PopulationGroup#1156461521076#0.6526656643346673#minLength</target> + <domain> + <fixed cardinality="3"> + <enumeration> + <value>13</value> + <value>14</value> + <value>45</value> + </enumeration> + </fixed> + </domain> + </factor> + <factor name="factor 4 (MatrixContinuous)" property="matrixcontinuous" type="real"> + <target>fr.ifremer.isisfish.entities.PopulationGroup#1156461521076#0.6526656643346673#minLength</target> + <domain> + <fixed cardinality="0"> + <reference coefficient="0.799"> + <mx name="test1"> + <dimension name="col1" size="3"> + <label>null()</label> + <label>null()</label> + <label>null()</label> + </dimension> + <dimension name="col2" size="2"> + <label>null()</label> + <label>null()</label> + </dimension> + <d>13.0</d> + <d>-14.0</d> + <d>21.0</d> + <d>2.0</d> + <d>12.0</d> + <d>-1.0</d> + </mx> + </reference> + </fixed> + </domain> + </factor> + <factor name="factor 5 (EquationContinuous)" property="equationcontinuous" type="real"> + <target>fr.ifremer.isisfish.entities.PopulationGroup#1156461521076#0.6526656643346673#maxLength</target> + <domain> + <fixed cardinality="0" variable="L1"> + <reference coefficient="0.1">45.0</reference> + </fixed> + </domain> + </factor> + <factor name="factor 6 (double continuous percentage)" property="continuous" type="real"> + <target>fr.ifremer.isisfish.entities.PopulationGroup#1142003453434#0.223499349929004#size</target> + <domain> + <fixed cardinality="5"> + <reference coefficient="5.0">14.0</reference> + </fixed> + </domain> + </factor> + </factors> +</experimentalDesign>