/** * Returns all values for the given key * * @param key key (case insensitive) * @return all values of the given header or {@code null}, if there is no such a key in this * instance */ public List<String> getValues(final String key) { Validate.notEmpty(key, "name cannot be empty"); @SuppressWarnings("unchecked") final List<String> result = (List<String>) values.get(key.toLowerCase()); return result == null || result.isEmpty() ? null : new ArrayList<String>(result); }
/** * Evaluates a solution. * * @param solution The solution to evaluate. * @throws JMException */ public void evaluate(Solution solution) throws JMException { writeModificationFile(solution); String energyPLANrunCommand = ".\\EnergyPLAN_SEP_2013\\EnergyPLAN.exe -i \".\\EnergyPLAN_SEP_2013\\energyPlan data\\Data\\RefModelForOptimization.txt\" -m \"modification.txt\" -ascii \"result.txt\" "; try { // Process process = new // ProcessBuilder(energyPLANrunCommand).start(); Process process = Runtime.getRuntime().exec(energyPLANrunCommand); process.waitFor(); process.destroy(); EnergyPLANFileParse epfp = new EnergyPLANFileParse(".\\result.txt"); energyplanmMap = epfp.parseFile(); Iterator it; Collection<String> col; col = (Collection<String>) energyplanmMap.get("CO2-emission (total)"); it = col.iterator(); solution.setObjective(0, Double.parseDouble(it.next().toString())); col = (Collection<String>) energyplanmMap.get("TOTAL ANNUAL COSTS"); it = col.iterator(); solution.setObjective(1, Double.parseDouble(it.next().toString())); // check warning col = (Collection<String>) energyplanmMap.get("WARNING"); if (col != null) { /* System.out.println("No warning"); } else {*/ @SuppressWarnings("rawtypes") Iterator it3 = col.iterator(); if (!it3.next().toString().equals("PP too small. Critical import is needed")) throw new IOException("warning!!" + it3.next().toString()); // System.out.println("Warning " + it3.next().toString()); } } catch (IOException e) { System.out.println("Energyplan.exe has some problem"); e.printStackTrace(); } catch (InterruptedException e) { System.out.println("Energyplan interrupted"); } }
/** * Indexes a set of reports, using Start and End tags output is a list of entries of the form: A: * time1,time2,time3 * * <p>If no matches, will return an empty array */ @SuppressWarnings("unchecked") public static Text[] indexGraph(Map<String, Report> reports) { org.apache.commons.collections.MultiMap index = new org.apache.commons.collections.MultiHashMap(); // map from start tag to opIds of nodes containing the ends for (Map.Entry<String, Report> report : reports.entrySet()) { Report start = report.getValue(); List<String> starts = start.get("Start"); if (starts != null) { for (String s : starts) { Report end = findMatchingEnd(reports, start, s); if (end == null) continue; List<String> endTL = end.get("Timestamp"); List<String> staTL = start.get("Timestamp"); if (staTL != null && endTL != null && staTL.size() > 0 && endTL.size() > 0) { // FIXME: perhaps parse more cleverly? double startT = Double.parseDouble(staTL.get(0)); double endT = Double.parseDouble(endTL.get(0)); Long diff = new Long((long) (1000 * (endT - startT))); index.put(s, diff); } } } } Text[] out = new Text[index.size()]; int i = 0; for (Object k : index.keySet()) { StringBuilder sb = new StringBuilder(); sb.append(k.toString()); sb.append(' '); Collection coll = (Collection) index.get(k); for (Object v : coll) { assert v instanceof Long : "how did a non-Long get into my collection?"; sb.append(v.toString()); sb.append(","); } sb.deleteCharAt(sb.length() - 1); Text t = new Text(sb.toString()); out[i++] = t; } return out; }
@SuppressWarnings("unchecked") public void evaluateConstraints(Solution solution) throws JMException { Iterator it; Collection<String> col; col = (Collection<String>) energyplanmMap.get("Maximumimport"); it = col.iterator(); int maximumImport = Integer.parseInt(it.next().toString()); double constrints = 2500 - maximumImport; if (constrints < 0.0) { solution.setOverallConstraintViolation(constrints); solution.setNumberOfViolatedConstraint(1); } else { solution.setOverallConstraintViolation(0.0); solution.setNumberOfViolatedConstraint(0); } }