コード例 #1
0
 public void test_RunSteadyStateCalculation_Newton() {
   HashMap<String, Object> problemParameters = new HashMap<String, Object>();
   problemParameters.put("JacobianRequested", new Boolean(true));
   problemParameters.put("StabilityAnalysisRequested", new Boolean(true));
   // iteration limit
   // tolerance
   HashMap<String, Object> methodParameters = new HashMap<String, Object>();
   methodParameters.put("Resolution", new Double(1e-9));
   methodParameters.put("Derivation Factor", new Double(1e-3));
   methodParameters.put("Use Newton", new Boolean(true));
   methodParameters.put("Use Integration", new Boolean(false));
   methodParameters.put("Use Back Integration", new Boolean(false));
   methodParameters.put("Accept Negative Concentrations", new Boolean(false));
   methodParameters.put("Iteration Limit", new Integer(50));
   // objective function
   CSteadyStateTask steadyStateTask =
       runSteadyStateCalculation(mDataModel, problemParameters, methodParameters);
   assertFalse(steadyStateTask == null);
   assertTrue(steadyStateTask.getResult() == CSteadyStateMethod.foundEquilibrium);
   CEigen eigenvalues = steadyStateTask.getEigenValues();
   assertFalse(eigenvalues == null);
   assertTrue(eigenvalues.getMaxrealpart() <= 0.0);
   assertTrue(eigenvalues.getNnegreal() + eigenvalues.getNreal() == eigenvalues.getR().size());
 }
コード例 #2
0
 public static CSteadyStateTask runSteadyStateCalculation(
     CCopasiDataModel dataModel,
     HashMap<String, Object> problemParameters,
     HashMap<String, Object> methodParameters) {
   CSteadyStateTask steadyStateTask =
       (CSteadyStateTask) dataModel.addTask(CCopasiTask.steadyState);
   if (steadyStateTask == null) return null;
   CSteadyStateProblem steadyStateProblem = (CSteadyStateProblem) steadyStateTask.getProblem();
   if (steadyStateProblem == null) return null;
   Set<String> keySet = problemParameters.keySet();
   for (Iterator<String> it = keySet.iterator(); it.hasNext(); ) {
     String key = (String) it.next();
     CCopasiParameter param = steadyStateProblem.getParameter(key);
     if (param == null) {
       return null;
     }
     Object o = problemParameters.get(key);
     if (o instanceof Double) {
       param.setDblValue(((Double) o).doubleValue());
     } else if (o instanceof Integer) {
       param.setIntValue(((Integer) o).intValue());
     } else if (o instanceof Boolean) {
       param.setBoolValue(((Boolean) o).booleanValue());
     } else if (o instanceof String) {
       param.setStringValue(((String) o));
     } else {
       System.err.println("Error. Unknown parameter type.");
     }
   }
   CNewtonMethod newtonMethod = (CNewtonMethod) steadyStateTask.getMethod();
   if (newtonMethod == null) {
     return null;
   }
   keySet = methodParameters.keySet();
   for (Iterator<String> it = keySet.iterator(); it.hasNext(); ) {
     String key = (String) it.next();
     CCopasiParameter param = newtonMethod.getParameter(key);
     if (param == null) {
       return null;
     }
     Object o = methodParameters.get(key);
     if (o instanceof Double) {
       param.setDblValue(((Double) o).doubleValue());
     } else if (o instanceof Integer) {
       param.setIntValue(((Integer) o).intValue());
     } else if (o instanceof Boolean) {
       param.setBoolValue(((Boolean) o).booleanValue());
     } else if (o instanceof String) {
       param.setStringValue(((String) o));
     } else {
       System.err.println("Error. Unknown parameter type.");
     }
   }
   boolean result = false;
   try {
     result = steadyStateTask.process(true);
   } catch (Exception e) {
     System.err.println("ERROR: " + e.getMessage());
   }
   if (!result) {
     return null;
   }
   return steadyStateTask;
 }