示例#1
0
  /**
   * * <br>
   * Updates the neural networks</br> <br>
   * Assumes that the *
   */
  private void trainNeuralNets(int id) {

    Train train =
        new ResilientPropagation(array_of_neural_nets[id], input_datas[id].getTrainingSet());

    int epoch = 0;
    while (train.getError() > error_allowed && epoch < max_epoch) {

      train.iteration();
      epoch++;
    }
  }
示例#2
0
  @SuppressWarnings("unchecked")
  @ApiMethod(name = "listOfTrains", path = "findmytrain/v1/listTrains")
  public List<String> listTrains(@Named("station") String station) throws ParseException {
    // This method should return the list of trains based on the station
    // if a trains stops at the station 'station' that will be added to the
    // 'trains' list
    final long ONE_MINUTE_IN_MILLIS = 60000;
    final int TIME_GAP_IN_MINUTES = 30;
    List<Train> trains = new ArrayList<Train>();
    List<Train> tempTrains = null;

    Date atRequest = new Date();
    SimpleDateFormat parser = new SimpleDateFormat("HH:mm");
    String serverTime = parser.format(atRequest);
    Date serverDate = parser.parse(serverTime);
    Date upperLimit = new Date(serverDate.getTime() + (TIME_GAP_IN_MINUTES * ONE_MINUTE_IN_MILLIS));
    Date lowerLimit = new Date(serverDate.getTime() - (TIME_GAP_IN_MINUTES * ONE_MINUTE_IN_MILLIS));

    // System.out.println("Server date : " + serverDate);
    // System.out.println("Server time : " + serverTime);

    PersistenceManager pm = PMF.get().getPersistenceManager();

    Query q = pm.newQuery(Train.class);

    try {
      tempTrains = (List<Train>) q.execute();
      List<Stop> tempStops = new ArrayList<Stop>();

      for (Train t : tempTrains) {
        tempStops = t.getStops();

        for (Stop s : tempStops) {
          // checking if a selected train stops at the selected
          // station
          if (s.getStation().equals(station)) {

            Date stationTime = parser.parse(s.getTime());

            // checking whether the station time is in between the
            // required time gap
            if (stationTime.after(lowerLimit) && stationTime.before(upperLimit)) {
              trains.add(t);
              break;
            }
          }
        }
      }

    } finally {
      q.closeAll();
    }

    // returning a string list instead of the train list

    List<String> result = new ArrayList<String>();

    for (Train t : trains) {
      result.add("From " + t.getStart() + " To " + t.getDestination() + "\n" + t.getTrainid());
    }
    return result;

    // returning the list of train objects
    // return trains;
  }