Beispiel #1
0
  /**
   * This method will authenticate the map, whether its an acceptable map or not.
   *
   * @return A string which indicates the map problems (null string for no problem)
   */
  public String validateMap() {

    // boolean verifyMap = true;
    String result = "";

    // Check if a state is isolated
    for (State tempState : myStateList) {
      Boolean isolated = true;
      for (Link tempLink : myLinkList) {
        if (tempLink.getSourceState().getStateID() == tempState.getStateID()
            || tempLink.getDestintionState().getStateID() == tempState.getStateID()) {
          isolated = false;
          break;
        }
      }
      if (isolated) result += "<br>" + tempState.getStateName() + " is an isolated state.";
    }

    // Check if there are more than one country
    if (myCountryList.size() <= 1) result += "<br>" + "The map has less than two countries.";

    // Check if each country has exactly one capital
    for (Country tempCountry : myCountryList) {
      int capitalCount = 0;
      for (State tempState : myStateList) {
        if (tempState.getCountryID() == tempCountry.getCountryID() && tempState.getIsCapital())
          capitalCount++;
      }
      if (capitalCount == 0)
        result += "<br>" + tempCountry.getCountryName() + " doesn't have any capital.";
      else if (capitalCount > 1)
        result += "<br>" + tempCountry.getCountryName() + " has more than one capital.";
    }
    return result;
  }
  public void getPropertyDataFeedList(
      PropertyDataDetailList pdfl, List<PropertyData> pdl, String dsName) throws Exception {
    PropertyDataDetailBuilder pfb;
    ZipCodes zc;
    City city;
    State state;
    for (PropertyData pd : pdl) {

      pfb = new PropertyDataDetailBuilder(pd);
      zc = coreDaoService.getZipCodesDao().findByPrimaryKey(pd.getZipCode());
      city = coreDaoService.getCityDao().findByPrimaryKey(zc.getCityId());
      state = coreDaoService.getStateDao().findByPrimaryKey(city.getStateId());
      pfb.setCity(city.getCityName());
      pfb.setState(state.getStateName());
      pfb.setStateCity(new StateCity(state, city));
      pfb.setDataSource(dsName);
      pfb.setFinancialList(
          coreDaoService.getPropertyFinancialDao().findWherePropertyDataUuidEquals(pd.getUuid()));
      pfb.setImageList(coreDaoService.getPropertyImagesDao().findByPropertyData(pd.getUuid()));
      pdfl.addToList(pfb.build());
    }
  }
Beispiel #3
0
  public static void readFile(Path path, List<State> estados, List<Simbolo> language) {
    try {

      BufferedReader bf = Files.newBufferedReader(path);

      String data;
      String values[];
      int numberOfStates;

      // First header line - states
      data = bf.readLine();
      values = data.split("\\s+");

      numberOfStates = Integer.parseInt(values[0].replace("#", ""));

      for (int i = 1; i <= numberOfStates; i++) {
        estados.add(new State(values[i]));
      }

      // Second header line - final states
      data = bf.readLine();
      values = data.split("\\s+");

      numberOfStates = Integer.parseInt(values[0].replace("#", ""));

      for (int i = 1; i <= numberOfStates; i++) {
        for (Iterator iter = estados.iterator(); iter.hasNext(); ) {
          State state = (State) iter.next();
          if (state.getStateName().matches(values[i])) state.setFinal(true);
        }
      }

      // Third header line - Language
      data = bf.readLine();
      values = data.split("\\s+");

      numberOfStates = Integer.parseInt(values[0].replace("#", ""));

      for (int i = 1; i <= numberOfStates; i++) {
        language.add(new Simbolo(values[i]));
      }

      bf.readLine(); // reads the separator

      // read transitions for each state
      for (int i = 0; i < estados.size(); i++) {
        String inputs[];

        data = bf.readLine();
        values = data.split("#");

        List<Transition> transitions = new LinkedList<>();

        for (int j = 0; j <= language.size(); j++) {
          inputs = values[j].trim().split("\\s");

          int counter = 0;

          while (counter < inputs.length) {
            for (State state : estados) {
              if (state.getStateName().matches(inputs[counter])) {
                if (j != language.size()) transitions.add(new Transition(language.get(j), state));
                else transitions.add(new Transition(state));
              }
            }
            counter++;
          }
        }

        estados.get(i).setTransitions(transitions);
      }

    } catch (Exception e) {
      System.err.println("Error al leer el archivo");
      System.err.println(e.toString());
    }
  }
Beispiel #4
0
  public static void main(String[] args) {

    List<State> estados = new LinkedList<>(); // supported state list
    List<Simbolo> language = new LinkedList<>(); // list with the simbols of the language

    if (args.length > 1) {
      Path path = Paths.get(args[0]);
      readFile(path, estados, language);

      String cadena = args[1];

      List<State> estadosActuales =
          new LinkedList<>(); // list with the current states of the automata
      List<State> estadosAuxiliares = new LinkedList<>(); // auxiliar list

      if (checkStringInLanguage(language, cadena)
          != true) { // check if the input string forms part of the language
        System.err.println(
            "La cadena introducida contiene elementos que no forman parte del lenguaje");
        return;
      }

      // add the clausure of the initial states to the current states of the automata to initialize
      // the automata
      estadosActuales.addAll(estados.get(0).clausure());
      imprimirEstados(estadosActuales);

      for (char c : cadena.toCharArray()) { // apply the current entry for each state
        System.out.println("Entrada: " + c); // prints
        for (State esta : estadosActuales) {

          estadosAuxiliares.addAll(esta.newInput(new Simbolo(Character.toString(c))));

          // clean repeated states
          for (int i = 0; i < estadosAuxiliares.size(); i++) {
            State t = estadosAuxiliares.get(i);
            for (int j = i + 1; j < estadosAuxiliares.size(); j++) {
              if (t.getStateName().matches(estadosAuxiliares.get(j).getStateName())) {
                estadosAuxiliares.remove(j);
                j--;
              }
            }
          }
        }

        // move the states from estadosAuxiliares to estadosActuales
        estadosActuales.removeAll(estadosActuales);

        estadosAuxiliares.forEach(
            estado -> {
              estadosActuales.add(estado);
            });

        estadosAuxiliares.removeAll(estadosAuxiliares);

        imprimirEstados(estadosActuales);
      }

      boolean success = false;

      // check if at least one of the remaining states it's a final state
      for (int u = 0; u < estadosActuales.size() && !success; u++) {
        if (estadosActuales.get(u).isFinal()) success = true;
      }

      if (success) // if at least one is final, the chain is aceppted
      System.out.println("CADENA ACEPTADA");
      else // if any of the remaining states is final, the chain is rejected
      System.out.println("CADENA RECHAZADA");
    }
  }
Beispiel #5
0
 // Prints the states of a list
 public static void imprimirEstados(List<State> estados) {
   System.out.println("Estados actuales: ");
   for (State estado : estados) {
     System.out.println("\t" + estado.getStateName());
   }
 }
  // 重构思想
  public static void AyalyzingPreLookAheadForRefactorDFS(String messageName) {
    if (messageName == null) {
      System.out.println("No input message to drive the automachine!");
      return;
    }

    LinkedList<Mission> errorSequenceList2 = new LinkedList<Mission>();

    if (kSteps > 0) {
      System.out.println();
      System.out.println(
          "Look ahead "
              + kSteps
              + " steps with message: "
              + messageMap.get(messageName)
              + "\nwhich is mapped into "
              + messageName
              + "billy refactor");
      System.out.println();
    }

    currentTime1 = System.nanoTime();

    if (tmpFoundList.size() != 0) {
      foundList = (ArrayList<MissionForRefactor>) tmpFoundList.clone();
      tmpFoundList.clear();
    }

    System.out.println("\n Possible right message sequences(billy refactor):\n");

    for (int i = 0; i < timedAutomataStateList.size(); i++) { // 从每个自动机的起始状态开始找
      ArrayList<String> placeArray;

      MissionForRefactor mfr;
      for (int index = 0; index < foundList.size(); index++) {
        mfr = foundList.get(index);

        if (!mfr.getFirstMessageName().equals(messageName)) continue; // 给定的消息在原来查找到的序列里不合适,结束本次循环

        placeArray = mfr.getPlaceArray();
        String tmpMessageSequence = mfr.getMessageSequenceWithoutFirstMessageName();
        boolean isFind = false;
        List<State> timedAutomataState = timedAutomataStateList.get(i);
        //		String stateName = timedAutomataState.get(0).getStateName();
        String stateName = placeArray.get(i);
        //		System.out.println("11 " + stateName);
        for (int j = 0; j < timedAutomataState.size(); j++) { // 根据起始状态的名字查找timedAutomataState
          State currentState = timedAutomataState.get(j);
          //			System.out.println("22 ");
          if (currentState.getStateName().equals(stateName)) { // 找到了对应名字的state
            List<String> innerList = currentState.getInnerMessageList();
            //				System.out.println("33 " + innerList.size());
            for (int k = 0; k < innerList.size(); k++) { // 内部消息都是可能的
              ArrayList<String> tmpPlaceArray = (ArrayList<String>) placeArray.clone();
              tmpPlaceArray.set(i, currentState.getEndStateName(innerList.get(k)));
              //					StringBuffer buffer=new StringBuffer(innerList.get(k));
              //
              //	synchronizedMoveInFindingMessageSeq(buffer,1,innerList.get(k),INNER_MESSAGE,tmpPlaceArray,i);
              //					printPlaceArray(tmpPlaceArray);
              //					queue.add(new Mission(innerList.get(k), (ArrayList<String>)
              // tmpPlaceArray.clone(), 1));
              if (tmpMessageSequence.equals(""))
                tmpFoundList.add(new MissionForRefactor(innerList.get(k), tmpPlaceArray));
              else
                tmpFoundList.add(
                    new MissionForRefactor(
                        tmpMessageSequence + " , " + innerList.get(k), tmpPlaceArray));
              System.out.println("*** " + tmpMessageSequence + " , " + innerList.get(k) + " ***");
              isFind = true;
            }

            List<String> sendList = currentState.getSendMessageList();
            // List<String>
            // receiveList=currentState.getReceiveMessageList();
            //				System.out.println("44 " + sendList.size());
            for (int k = 0; k < sendList.size(); k++) { // 发送必须和接收配对,才是可能的
              ArrayList<String> tmpPlaceArray = (ArrayList<String>) placeArray.clone();
              int temp = AnalyzeMessageSequence.findInAllAuto(sendList.get(k), tmpPlaceArray);
              if (temp != -1) {
                tmpPlaceArray.set(i, currentState.getEndStateName(sendList.get(k)));
                //						printPlaceArray(tmpPlaceArray);
                //						queue.add(new Mission(sendList.get(k),
                //								(ArrayList<String>) tmpPlaceArray.clone(),
                //								1));
                if (tmpMessageSequence.equals(""))
                  tmpFoundList.add(new MissionForRefactor(sendList.get(k), tmpPlaceArray));
                else
                  tmpFoundList.add(
                      new MissionForRefactor(
                          tmpMessageSequence + " , " + sendList.get(k), tmpPlaceArray));
                System.out.println("*** " + tmpMessageSequence + " , " + sendList.get(k) + " ***");
                isFind = true;
              }
            }
            //				System.out.println("55 " + queue.size());
            break; // 找到了第一个起始状态的描述,不再进行内循环
          }
        }
        if (!isFind) {
          boolean isMissionExist = false;
          for (Mission mission : errorSequenceList2) { // 判断一下errorSequenceList中原来是不是已经加了这个任务
            if (mission.getPreviousMessage().equals(mfr.getMessageSequence())) {
              isMissionExist = true;
              break;
            }
          }

          if (!isMissionExist)
            errorSequenceList2.add(
                new Mission(
                    mfr.getMessageSequence(),
                    mfr.getPlaceArray(),
                    kSteps)); // 如果mission没有下文了,则存入错误组合链表,供最后集中打印
        }
      }
    }

    // 再次判断是否错误组合中有正确组合的部分,否则去掉
    for (MissionForRefactor mr : foundList) {
      for (int i = 0; i < errorSequenceList2.size(); i++) {
        Mission mission = errorSequenceList2.get(i);
        if (mr.getMessageSequence().contains(mission.getPreviousMessage()))
          errorSequenceList2.remove(mission);
      }
    }

    System.out.println("\n Possible error message sequences:\n");
    for (int index = 0; index < errorSequenceList2.size(); index++) {
      MissionForRefactor mfr = errorSequenceList2.get(index).toReconstrcut();
      if (!mfr.getFirstMessageName().equals(messageName)) continue; // 给定的消息在原来查找到的序列里不合适,结束本次循环
      ArrayList<String> placeArray = mfr.getPlaceArray();
      String tmpMessageSequence = mfr.getMessageSequenceWithoutFirstMessageName();
      System.out.print("Warning: " + tmpMessageSequence + "\t");

      System.out.print("( ");
      for (int k = 0; k < placeArray.size(); k++) {
        System.out.print(
            placeArray.get(k)
                + "("
                + IImageKeys.automataFilesName
                    .get(k)
                    .substring(
                        IImageKeys.automataFilesName.get(k).indexOf('/') + 1,
                        IImageKeys.automataFilesName.get(k).lastIndexOf('.'))
                + ") ");
      }
      System.out.println(")");
    }

    boolean isFind = true;
    while (isFind) {
      isFind = false;
      for (int i = 0; i < errorSequenceList.size(); i++) {
        Mission mission = errorSequenceList.get(i);
        if (!mission.getFirstMessageName().equals(messageName)) {
          continue;
        }
        isFind = true;
        System.out.println(
            "Warning: " + mission.getMessageSequenceWithoutFirstMessageName() + "\t");

        mission.setPreviousMessage(mission.getMessageSequenceWithoutFirstMessageName());

        ArrayList<String> placeArray = mission.getPlaceList();
        System.out.print("( ");
        for (int k = 0; k < placeArray.size(); k++) {
          System.out.print(
              placeArray.get(k)
                  + "("
                  + IImageKeys.automataFilesName
                      .get(k)
                      .substring(
                          IImageKeys.automataFilesName.get(k).indexOf('/') + 1,
                          IImageKeys.automataFilesName.get(k).lastIndexOf('.'))
                  + ") ");
        }
        System.out.println(")");
      }
    }

    long current2 = System.nanoTime();
    timeList.add((current2 - currentTime1) / 1000);
    System.out.println(
        "\n The execution time of analysis with reconstruct is: "
            + (current2 - currentTime1) / 1000
            + " us");
    System.out.println(
        "*****************************************************************************");
  }
  private static void AyalyzingPreLookAheadWithMultiAutomataDFS() {
    if (queue.isEmpty()) {

      for (int i = 0;
          i < timedAutomataStateList.size();
          i++) { // 从每个自动机的起始状态开始找(billy:这边的size 表示有几个自动机)
        ArrayList<String> placeArray = new ArrayList<String>(timedAutomataStateList.size());
        AnalyzeMessageSequence.initPlaceArray(placeArray);
        List<State> timedAutomataState = timedAutomataStateList.get(i); // billy:得到第i个自动机 里面的所有状态
        String stateName = placeArray.get(i); // billy:第i个自动机的 名字
        for (int j = 0;
            j < timedAutomataState.size();
            j++) { // 根据起始状态的名字查找timedAutomataState (billy:指第i个自动机的每个状态)
          State currentState = timedAutomataState.get(j);
          if (currentState.getStateName().equals(stateName)) { // 找到了对应名字的state
            List<String> innerList = currentState.getInnerMessageList();
            for (int k = 0; k < innerList.size(); k++) { // 内部消息都是可能的
              ArrayList<String> tmpPlaceArray = (ArrayList<String>) placeArray.clone();
              tmpPlaceArray.set(
                  i,
                  currentState.getEndStateName(
                      innerList.get(k))); // billy:把内部消息对应的状态  staname放入到tmp
              queue.add(
                  new Mission(innerList.get(k), (ArrayList<String>) tmpPlaceArray.clone(), 1));
            }
            // System.out.println("queue whether empty");
            List<String> sendList = currentState.getSendMessageList();
            for (int k = 0; k < sendList.size(); k++) { // 发送必须和接收配对,才是可能的
              ArrayList<String> tmpPlaceArray = (ArrayList<String>) placeArray.clone();
              int temp = AnalyzeMessageSequence.findInAllAuto(sendList.get(k), tmpPlaceArray);
              if (temp != -1) {
                tmpPlaceArray.set(i, currentState.getEndStateName(sendList.get(k)));
                //								printPlaceArray(tmpPlaceArray);
                queue.add(
                    new Mission(sendList.get(k), (ArrayList<String>) tmpPlaceArray.clone(), 1));
              }
            }
            //		System.out.println("55 " + queue.size());
            break; // 找到了第一个起始状态的描述,不再进行内循环
          }
        }
      }
    }
    System.out.println("\n Possible right message sequences:\n");
    while (!queue.isEmpty()) {
      Mission m = queue.poll(); // 从队列取出,删

      if (m.getSteps() < kSteps) {
        Stack.push(m);

        while (!Stack.isEmpty()) {
          Mission sm = Stack.pop();
          String buffer = sm.getPreviousMessage();
          ArrayList<String> placeArray = (ArrayList<String>) sm.getPlaceList().clone();
          boolean isFind = false;
          for (int i = 0; i < timedAutomataStateList.size(); i++) {
            List<State> timedAutomataState = timedAutomataStateList.get(i);

            for (int j = 0; j < timedAutomataState.size(); j++) { // 根据下一状态的名字查找timedAutomataState
              State currentState = timedAutomataState.get(j);
              //	System.out.println("88 "+currentState.getStateName());
              //	AnalyzeMessageSequence.printPlaceArray(placeArray);
              if (currentState.getStateName().equals(placeArray.get(i))) { // 在自动机i中找到了对应名字的state
                List<String> innerList = currentState.getInnerMessageList();
                //	System.out.println("99 " + innerList.size());
                for (int k = 0; k < innerList.size(); k++) { // 内部消息都是可能的
                  ArrayList<String> tmpPlaceArray = (ArrayList<String>) placeArray.clone();
                  tmpPlaceArray.set(i, currentState.getEndStateName(innerList.get(k)));
                  //								printPlaceArray(tmpPlaceArray);
                  if (sm.getSteps() + 1 == kSteps) {
                    kqueue.add(
                        new Mission(
                            buffer + " , " + innerList.get(k),
                            (ArrayList<String>) tmpPlaceArray.clone(),
                            sm.getSteps() + 1));
                    Mission km = kqueue.poll();
                    foundList.add(
                        new MissionForRefactor(km.getPreviousMessage(), km.getPlaceList()));
                    System.out.println("---" + km.getPreviousMessage() + "---");
                    isFind = true;

                  } else {
                    // tmpPlaceArray.add("visited");
                    Stack.push(
                        new Mission(
                            buffer + " , " + innerList.get(k),
                            (ArrayList<String>) tmpPlaceArray.clone(),
                            sm.getSteps() + 1));
                    isFind = true;
                  }
                }

                List<String> sendList = currentState.getSendMessageList();
                //
                for (int k = 0; k < sendList.size(); k++) { // 发送必须和接收配对,才是可能的
                  ArrayList<String> tmpPlaceArray = (ArrayList<String>) placeArray.clone();
                  if (AnalyzeMessageSequence.findInAllAuto(sendList.get(k), tmpPlaceArray) != -1) {
                    tmpPlaceArray.set(i, currentState.getEndStateName(sendList.get(k)));
                    if (sm.getSteps() + 1 == kSteps) {
                      kqueue.add(
                          new Mission(
                              buffer + " , " + sendList.get(k),
                              (ArrayList<String>) tmpPlaceArray.clone(),
                              sm.getSteps() + 1));
                      Mission km = kqueue.poll();
                      foundList.add(
                          new MissionForRefactor(km.getPreviousMessage(), km.getPlaceList()));
                      System.out.println("---" + km.getPreviousMessage() + "---");
                      isFind = true;

                    } else {
                      Stack.push(
                          new Mission(
                              buffer + " , " + sendList.get(k),
                              (ArrayList<String>) tmpPlaceArray.clone(),
                              sm.getSteps() + 1));
                      isFind = true;
                    }
                  }
                }
              } // end current if
            }
          } // end out for //end inner for
          if (!isFind) { //
            boolean isMissionExist = false;
            for (Mission mission : errorSequenceList) { // 判断一下errorSequenceList中原来是不是已经加了这个任务
              if (mission.getPreviousMessage().equals(sm.getPreviousMessage())) {
                isMissionExist = true;
                break;
              }
            }
            if ((!isMissionExist)
            //								&&(!isMissionLeave)&&(!flag)
            ) errorSequenceList.add(sm); // 如果mission没有下文了,则存入错误组合链表,供最后集中打印
            //			for(int j=0;j<errorSequenceList.size();j++){
            //				Mission mission=errorSequenceList.get(j);
            //				System.out.println("errorsequecne"+mission.getPreviousMessage());}
          }
        } // end empty

      } // end if k
      else {
        System.out.println("---" + m.getPreviousMessage() + "---(billy)");
      }
    } // end queue

    for (MissionForRefactor mr : foundList) {
      for (int i = 0; i < errorSequenceList.size(); i++) {
        Mission mission = errorSequenceList.get(i);
        if (mr.getMessageSequence().contains(mission.getPreviousMessage()))
          errorSequenceList.remove(mission); // 首次出现的mission
      }
    }

    // 打印所有错误的组合
    System.out.println("\n Possible error message sequences(billy):\n");
    for (int i = 0; i < errorSequenceList.size(); i++) {
      Mission m = errorSequenceList.get(i);
      System.out.print("Warning: " + m.getPreviousMessage() + "\t");
      ArrayList<String> list = m.getPlaceList();

      System.out.print("( ");
      for (int k = 0; k < list.size(); k++) {
        System.out.print(
            list.get(k)
                + "("
                + IImageKeys.automataFilesName
                    .get(k)
                    .substring(
                        IImageKeys.automataFilesName.get(k).indexOf('/') + 1,
                        IImageKeys.automataFilesName.get(k).lastIndexOf('t'))
                + ") ");
      }
      System.out.println(")");
    }
    if (kSteps > 0) {
      // System.out.println("Look ahead " + kSteps + " steps " +
      // (withControllability!=0?"with":"without") +
      // " controllability by " +
      // (isDepthSearchFirst!=0?"breadth search first.":"depth search first."));
      long current2 = System.nanoTime();
      timeList.add((current2 - currentTime1) / 1000);
      System.out.println(
          "\nThe execution time of initial Lookahead is:  "
              + (current2 - currentTime1) / 1000
              + " us");
    } else {
      System.out.println(
          "The execution time of analysis without Pre-Lookahead is: "
              + (System.nanoTime() - currentTime1) / 1000
              + " us");
    }
    System.out.println(
        "--------------深度---------------多自动机主动监控-------------------------------------------");
  } // end ayalyzingpre dfs