Beispiel #1
0
    private TCG toTCG() {
      TCG graph = new TCG();
      // 找当前活跃节点,应该是place
      CustomedPlace p = this.lastActivePlace;
      if (null == p) return null;
      TCGNode tnode = new TCGNode(String.valueOf(p.getId()));
      this.startTCGNode = tnode;
      graph.addNode(tnode);
      // 给lastActivePlace的直接后继加弧,别的都由普通库所加弧
      LinkedList<PlaceToTransition> oArc = lastActivePlace.getOutArc();
      for (PlaceToTransition ptt : oArc) {
        CustomedTransition cto = ptt.t;
        TCGNode newnode =
            new TCGNode(
                String.valueOf(cto.getId()),
                new TimeDesc(0, cto.getInnerTime()[0]),
                new TimeDesc(0, cto.getInnerTime()[1]));
        graph.addNode(newnode);
        TimeConstraint tc =
            new TimeConstraint(
                tnode, newnode, new TimeDesc(0, 0), TimeDesc.MAXTIME(), TimeConstraint.DIRECT);
        graph.addConstraint(tc);
      }
      /*Set<String> pSet = pttList.keySet();
      for(Iterator it=pSet.iterator();it.hasNext();){
      	String id = (String)it.next();
      	String idArray[] = id.split(",");
      	if(null != idArray && idArray.length > 1
      			&& null != idArray[0] &&
      			idArray[0].equals(String.valueOf(p.getId()))
      			&& null != idArray[1]){
      		PlaceToTransition pttt = (PlaceToTransition)pttList.get(idArray[1]);
      		if(pttt!=null){
      			CustomedTransition ct = pttt.t;
      			TCGNode newnode = new TCGNode(idArray[1],new TimeDesc(0,ct.getInnerTime()[0]),new TimeDesc(0,ct.getInnerTime()[1]));
      			graph.addNode(newnode);
      			TimeConstraint tc = new TimeConstraint(tnode,newnode,new TimeDesc(0,0),TimeDesc.MAXTIME(),TimeConstraint.DIRECT);
      		    graph.addConstraint(tc);
      		}
      	}
      }*/
      // 遍历所有库所,加弧和变迁,加的是前置后置,绝对时间约束
      Set<Integer> pSet = this.fpList.keySet();
      for (Iterator<Integer> it = pSet.iterator(); it.hasNext(); ) {
        Integer id = (Integer) it.next();
        CustomedPlace cp = fpList.get(id);
        if (cp.isVisited() || cp.isInvalid() || cp == this.lastActivePlace) ;
        LinkedList<TransitionToPlace> inArc = cp.getInArc();
        LinkedList<PlaceToTransition> outArc = cp.getOutArc();
        if (inArc != null && outArc != null) {
          for (TransitionToPlace ttp : inArc) {
            CustomedTransition cti = ttp.t;
            for (PlaceToTransition ptt : outArc) {
              CustomedTransition cto = ptt.t;
              if (cti != null && cto != null) {
                TCGNode t1 =
                    new TCGNode(
                        String.valueOf(cti.getId()),
                        new TimeDesc(0, cti.getInnerTime()[0]),
                        new TimeDesc(0, cti.getInnerTime()[1]));
                TCGNode t2 =
                    new TCGNode(
                        String.valueOf(cto.getId()),
                        new TimeDesc(0, cto.getInnerTime()[0]),
                        new TimeDesc(0, cto.getInnerTime()[1]));
                graph.addNode(t1);
                graph.addNode(t2);
                TimeConstraint tc =
                    new TimeConstraint(
                        t1, t2, new TimeDesc(0, 0), TimeDesc.MAXTIME(), TimeConstraint.DIRECT);
                graph.addConstraint(tc);
              }
            }
          }
        }
      }
      // 遍历所有变迁,加截止时间约束
      Timestamp startTime = this.parentProcess.startTime;
      //	Timestamp lastUpdateTime = this.lastActivePlace.getAvailableTime();
      Timestamp lastUpdateTime = new Timestamp(System.currentTimeMillis());
      Set<Integer> tSet = this.ftList.keySet();
      for (Iterator<Integer> it = tSet.iterator(); it.hasNext(); ) {
        Integer id = (Integer) it.next();
        CustomedTransition ct = ftList.get(id);
        if (ct.isVisited() || ct.isInvalid()) ;

        TCGNode has = graph.getNode(String.valueOf(ct.getId()));
        if (null == has) {
          has =
              new TCGNode(
                  String.valueOf(ct.getId()),
                  new TimeDesc(0, ct.getInnerTime()[0]),
                  new TimeDesc(0, ct.getInnerTime()[1]));
          graph.addNode(has);
        }
        if (ct.getDeadLine() != 0) {
          @SuppressWarnings("deprecation")
          int gap = lastUpdateTime.getMinutes() - startTime.getMinutes();
          int relative = ct.getDeadLine() - gap;
          @SuppressWarnings("unused")
          TimeConstraint tc1 =
              new TimeConstraint(
                  this.startTCGNode,
                  has,
                  new TimeDesc(0, 0),
                  new TimeDesc(0, relative),
                  TimeConstraint.ASSIGNED);
        }
      }
      return graph;
    }