Package org.xilaew.jampl

Examples of org.xilaew.jampl.JAMPL


import org.xilaew.jampl.JAMPL.SolveResult;

public class AmplJamplTest {

  public static void main(String[] args) throws IOException {
    JAMPL jampl = AmplFactory.createJAMPL();
    jampl.setSolver("cplex");
    jampl.loadModel("output/assignment.mod");
    jampl.loadData("output/assignment0.dat");
    SolveResult result = jampl.solve();
    printResult(result);
    jampl.setSolver("couenne");
    printResult(jampl.solve());
    System.out.println("found a result!");
    System.out.println("a is: "+jampl.getParameter("a"));
    System.out.println("x is: "+jampl.getVariable("x"));
    jampl.kill();
  }
View Full Code Here


    TestSuite result = factory.createTestSuite();
    SUT sut = factory.createSUT();
    sut.setName(tcgActivity.getClassName());
    sut.setPackageName(tcgActivity.getPackageName());
    result.getSut().add(sut);
    JAMPL ampl = AmplFactory.createJAMPL();
    String solver = null;

    // Transform Model to AMPL
    String amplModel = ActTCG2AMPLModel.transform(tcgActivity);
    ampl.getCli().sendCommand(amplModel);
    // Create one Testcase per Path
    for (Path p : paths) {
      // Generate AMPL Data for each Path
      String data = Path2AMPLData.transform(p);
      ampl.loadData(data);
      if (solver == null) {
        InputDialog d = new InputDialog(null, "W�hlen sie den Solver",
            "Welchen Solver m�chten sie verwenden", "couenne", null);
        d.create();
        d.open();
        solver = d.getValue();
        ampl.setSolver(solver);
      }
      // Solve the Model and Data to get Input data
      SolveResult solved;
      try {
        solved = ampl.solve();
      } catch (IOException e) {
        ampl = AmplFactory.createJAMPL();
        ampl.setSolver(solver);
        ampl.loadModel(ActTCG2AMPLModel.transform(tcgActivity));
        System.out.println("RESET!!!");
        ampl.loadData(Path2AMPLData.transform(p));
        try {
          solved = ampl.solve();
        } catch (IOException e1) {
          e1.printStackTrace();
          break;
        }
      }
      // Read Values from Solver and store in Model
      if (solved == SolveResult.Solved) {
        TestCase tc = factory.createTestCase();
        result.getTests().add(tc);
        FunctionCall func = factory.createFunctionCall();
        func.setName(tcgActivity.getName());
        func.setActivity(tcgActivity);
        tc.setFunction(func);
        for (TCGVariable var : tcgActivity.getVariables()) {
          Value v = factory.createValue();
          v.setName(var.getName());
          v.setVariable(var);
          if (var.isIsParameter()) {
            Double value = null;
            try {
              value = ampl.getParameter(var.getName());
            } catch (IOException e) {
             
              e.printStackTrace();
              continue;
            }
            v.setValue(value);
            switch (var.getUsage()) {
            case IN_PARAMETER:
              func.getParameters().add(v);
              break;
            case OUT_PARAMETER:
              tc.getTestForValue().add(v);
              break;
            case INOUT_PARAMETER:
              // XXX INOUT parameters currently can not be handled
              // since there is only one value. For in/out
              // Parameters a pre and a post Value would be
              // necessary.
              // func.getParameters().add(v); //@pre
              // tc.getTestForValue().add(v); //post
              break;
            case RETURN_PARAMETER:
              tc.getTestForValue().add(v);
              break;
            default:
              break;
            }
          } else {
            List<Double> trace = null;
            try {
              trace = ampl.getVariable(var.getName());
            } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              continue;
            }
View Full Code Here

TOP

Related Classes of org.xilaew.jampl.JAMPL

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.