@Override protected void initFlow(HierarchicalConfiguration flowCfg) { // int node = flowCfg.getInt("[@node]"); int inLink = flowCfg.getInt("[@inLink]", -1); int outLink = flowCfg.getInt("[@outLink]", -1); // int next = flowCfg.getInt("[@next]"); int no = flowCfg.getInt("[@no]", 0); Node node; Node next; if (inLink != -1) { Link link = idToLinkMap.get(Id.create(inLink, Link.class)); node = link.getFromNode(); next = link.getToNode(); } else { Link link = idToLinkMap.get(Id.create(outLink, Link.class)); node = link.getToNode(); next = link.getFromNode(); } int nodeId = Integer.parseInt(node.getId().toString()); int nextId = Integer.parseInt(next.getId().toString()); flows[nodeId] = new MATSimFlow(nodeId, inLink, outLink, nextId, no); }
/** * produces a Id whose prefix up to row is identical to this, followed by a digit with value * column, followed by a suffix of digits with value suffixDigits. * * @param row the length of the prefix * @param column the value of the following digit * @param suffixDigit the value of the suffix digits * @param b power of 2 of the base * @return the resulting Id */ public Id getDomainPrefix(int row, int column, int suffixDigit, int b) { Id res = new Id(Id); res.setDigit(row, column, b); for (int i = 0; i < row; i++) { res.setDigit(i, suffixDigit, b); } return build(res.Id); }
/** * Checks if this Id is between two given ids ccw (inclusive) and cw (exclusive) on the circle * * @param ccw the counterclockwise id * @param cw the clockwise id * @return true if this is between ccw (inclusive) and cw (exclusive), false otherwise */ public boolean isBetween(Id ccw, Id cw) { if (ccw.equals(cw)) { return false; } if (ccw.clockwise(cw)) { return this.clockwise(cw) && !this.clockwise(ccw); } else { return !this.clockwise(ccw) || this.clockwise(cw); } }
/** * produces a set of ids (keys) that are evenly distributed around the id ring. One invocation * produces the i-th member of a set of size num. The set is evenly distributed around the ring, * with an offset given by this Id. The set is useful for constructing, for instance, Scribe trees * with disjoint sets of interior nodes. * * @param num the number of Ids in the set (must be <= 2^b) * @param b the routing base (as a power of 2) * @param i the index of the requested member of the set (0<=i<num; the 0-th member is this) * @return the resulting set member, or null in case of illegal arguments */ public Id getAlternateId(int num, int b, int i) { if (num > (1 << b) || i < 0 || i >= num) { return null; } Id res = new Id(Id); int digit = res.getDigit(numDigits(b) - 1, b) + ((1 << b) / num) * i; res.setDigit(numDigits(b) - 1, digit, b); return build(res.Id); }
public static void main(String[] args) { String dir = "d:\\PP-rad\\poznan\\"; String networkFile = dir + "network.xml"; String linkStats = dir + "40.linkstats.txt.gz"; String polygonFile = dir + "poznan_polygon\\poznan_city_polygon.shp"; boolean includeBorderLinks = false; String filteredLinkStats = dir + "40.linkstats-filtered.txt.gz"; Geometry polygonGeometry = PolygonBasedFilter.readPolygonGeometry(polygonFile); Predicate<Link> linkInsidePolygonPredicate = PolygonBasedFilter.createLinkInsidePolygonPredicate(polygonGeometry, includeBorderLinks); Scenario scenario = ScenarioUtils.createScenario(VrpConfigUtils.createConfig()); MatsimNetworkReader nr = new MatsimNetworkReader(scenario); nr.readFile(networkFile); Map<Id<Link>, ? extends Link> linkMap = scenario.getNetwork().getLinks(); try (BufferedReader br = IOUtils.getBufferedReader(linkStats); PrintWriter pw = new PrintWriter(IOUtils.getBufferedWriter(filteredLinkStats))) { String header = br.readLine(); pw.println(header); String line; while ((line = br.readLine()) != null) { String linkId = new StringTokenizer(line).nextToken(); // linkId - first column Link link = linkMap.get(Id.create(linkId, Link.class)); if (linkInsidePolygonPredicate.apply(link)) { pw.println(line); } } } catch (IOException e) { throw new RuntimeException(e); } }
// 循环处理每个需要处理的程序对象 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { // 定义一个文件输出流,用于生成额外的文件 PrintStream ps = null; try { // 遍历每个被@Persistent修饰的class文件 for (Element t : roundEnv.getElementsAnnotatedWith(Persistent.class)) { // 获取正在处理的类名 Name clazzName = t.getSimpleName(); // 获取类定义前的@Persistent Annotation Persistent per = t.getAnnotation(Persistent.class); // 创建文件输出流 ps = new PrintStream(new FileOutputStream(clazzName + ".hbm.xml")); // 执行输出 ps.println("<?xml version=\"1.0\"?>"); ps.println("<!DOCTYPE hibernate-mapping PUBLIC"); ps.println(" \"-//Hibernate/Hibernate " + "Mapping DTD 3.0//EN\""); ps.println(" \"http://www.hibernate.org/dtd/" + "hibernate-mapping-3.0.dtd\">"); ps.println("<hibernate-mapping>"); ps.print(" <class name=\"" + t); // 输出per的table()的值 ps.println("\" table=\"" + per.table() + "\">"); for (Element f : t.getEnclosedElements()) { // 只处理成员变量上的Annotation if (f.getKind() == ElementKind.FIELD) // ① { // 获取成员变量定义前的@Id Annotation Id id = f.getAnnotation(Id.class); // ② // 当@Id Annotation存在时输出<id.../>元素 if (id != null) { ps.println( " <id name=\"" + f.getSimpleName() + "\" column=\"" + id.column() + "\" type=\"" + id.type() + "\">"); ps.println(" <generator class=\"" + id.generator() + "\"/>"); ps.println(" </id>"); } // 获取成员变量定义前的@Property Annotation Property p = f.getAnnotation(Property.class); // ③ // 当@Property Annotation存在时输出<property.../>元素 if (p != null) { ps.println( " <property name=\"" + f.getSimpleName() + "\" column=\"" + p.column() + "\" type=\"" + p.type() + "\"/>"); } } } ps.println(" </class>"); ps.println("</hibernate-mapping>"); } } catch (Exception ex) { ex.printStackTrace(); } finally { if (ps != null) { try { ps.close(); } catch (Exception ex) { ex.printStackTrace(); } } } return true; }