Exemple #1
0
  public static boolean are_d_connected(AbstractVariable x1, AbstractVariable x2, Vector evidence)
      throws RemoteException {
    // Find all paths between x1 and x2, then see if there is some path which is
    // d-connecting given the evidence. If so, return true, otherwise false.

    Hashtable path_sets = new Hashtable(); // HEY !!! THIS OUGHT TO BE CACHED SOMEWHERE !!!
    PathAnalysis.compile_paths(x1, x2, path_sets);

    Vector path_set = (Vector) path_sets.get(new VariablePair(x1, x2));
    if (path_set == null)
      // No connections whatsoever.
      return false;

    Enumeration path_set_enum = path_set.elements();
    while (path_set_enum.hasMoreElements()) {
      AbstractVariable[] path = (AbstractVariable[]) path_set_enum.nextElement();
      if (is_d_connecting(path, evidence)) {
        System.err.print("PathAnalysis.are_d_connected: path ");
        int i;
        for (i = 0; i < path.length; i++) System.err.print(path[i].get_name() + " ");
        System.err.print("is d-connected given evidence ");
        for (i = 0; i < evidence.size(); i++)
          System.err.print(((AbstractVariable) evidence.elementAt(i)).get_name() + " ");
        System.err.println("");
        return true;
      }
    }

    return false;
  }
  /**
   * This Method returns the 2D Array which is the list of the Items for the selected WorkOrder of
   * the Customer.
   *
   * @param workorderId - WorkOrder Id Foreign Key of WRK_ORDR_DETS table
   * @return Object[][] - 2D Array which is List of the Items for the WorkOrder
   */
  public Object[][] getWorkOrderItems(long workorderId) throws RemoteException {

    WrkOrdrDets wrkordrdts_obj = new WrkOrdrDets(conn);

    RHCCBlgKeys blgkeys_obj = new RHCCBlgKeys(conn);

    Vector workorderdetList = wrkordrdts_obj.getProductList(workorderId);

    // Hashtable BSysList = (Hashtable) USFEnv.getBillSystems();
    BlgSys blgsys = new BlgSys();

    Hashtable BSysList = (Hashtable) blgsys.searchBlgSys();

    Enumeration BSys = BSysList.keys();

    // The 2-Dimensional array to hold the Items Billing System wise.
    Object[][] prodList = new Object[BSysList.size()][workorderdetList.size() + 1];

    // The Number of Billing Systems are assumed to be equal to the
    // Static Load Billing Systems Hashtable size. The Billing Systems will
    // be in order starting from 1 and incrementing by one.
    for (int i = 0; i < BSysList.size(); i++) {
      // Set the 2D array to store the Billing System as the first element
      // of each row.
      prodList[i][0] = String.valueOf(i + 1);
    }

    // Loop throught the WorkOrder Items List and place them in the appropriate
    // positions in the 2D array.
    for (int j = 0; j < workorderdetList.size(); j++) {
      // Determine the Billing System of the Product
      Vector tmpVector = new Vector();

      WrkOrdrDets workorderObj = (WrkOrdrDets) workorderdetList.elementAt(j);

      RHCCBlgKeys bkObj =
          blgkeys_obj.searchRHCCBlgKeys(((WrkOrdrDets) workorderdetList.elementAt(j)).getRBKID());
      int bsid = (new Long(bkObj.getBsId())).intValue();

      tmpVector.addElement(bkObj);
      tmpVector.addElement(workorderObj);

      // Based on the Billing System Id retreived place the Product Object
      // in the 2D array.
      int k = 1;
      while (prodList[bsid - 1][k] != null) {
        k = k + 1;
      }
      prodList[bsid - 1][k] = tmpVector;
    }

    // Return the 2D array
    return prodList;
  }
 private void executeTestCase124() {
   try {
     Hashtable hash = dbxmlutil.getAllPanelAttribute(null);
     int s = (int) hash.size();
     if (s == 0) {
       System.out.println("CATS-JCF-API-DXU-124   ---> PASSED");
     } else {
       System.out.println("CATS-JCF-API-DXU-124   ---> FAILED");
     }
   } catch (Exception e) {
     // e.printStackTrace();
   }
 }
Exemple #4
0
 public String[] getUserList() throws RemoteException {
   Vector<String> res = new Vector<String>();
   for (ChatUser CU : userstable.values()) {
     res.add(CU.getName());
   }
   return res.toArray(new String[] {});
 }
Exemple #5
0
 public void sendMessage(ChatMessage m) throws RemoteException {
   Vector<String> fallidos = new Vector<String>();
   for (String uname : userstable.keySet()) {
     try {
       userstable.get(uname).sendMessage(m);
     } catch (Exception E) {
       fallidos.add(uname);
       System.out.println("no se lo he podido enviar a " + uname);
     }
   }
   for (String uname : fallidos) {
     try {
       leaveUser(userstable.get(uname));
     } catch (Exception E) {
       System.out.println("realmente " + uname + " se ha ido , lo borro");
       userstable.remove(uname);
       broadcastLeaving(uname);
     }
   }
 }
Exemple #6
0
  public static void compile_paths(AbstractVariable x1, AbstractVariable x2, Hashtable path_sets)
      throws RemoteException {
    Vector path_set = new Vector();
    Stack path_stack = new Stack();

    find_all_paths(x1, x2, path_set, path_stack);

    VariablePair vp = new VariablePair(x1, x2);
    // System.err.println( "  PathAnalysis.compile_paths: put a path for "+vp );
    path_sets.put(vp, path_set);
  }
  /**
   * When this class is loaded, preload the cache with a few items which we think will often be
   * needed. This can avoid the necessity of running a belief network context in simple problems.
   */
  static {
    System.err.println("PiHelperLoader.static: preload the helper cache.");

    helper_cache = new Hashtable();
    Vector seq = new Vector();

    seq.addElement(riso.distributions.ConditionalDiscrete.class);
    seq.addElement(riso.distributions.Discrete.class);

    helper_cache.put(
        new HelperCacheKey("pi", seq),
        riso.distributions.computes_pi.ConditionalDiscrete_Discrete.class);

    seq = new Vector();
    seq.addElement(riso.distributions.Discrete.class);

    helper_cache.put(
        new HelperCacheKey("lambda", seq), riso.distributions.computes_lambda.Discrete.class);

    seq = new Vector();
    seq.addElement(riso.distributions.AbstractDistribution.class);
    seq.addElement(riso.distributions.AbstractDistribution.class);

    helper_cache.put(
        new HelperCacheKey("pi_message", seq),
        riso.distributions.computes_pi_message.AbstractDistribution_AbstractDistribution.class);

    seq = new Vector();
    seq.addElement(riso.distributions.ConditionalDiscrete.class);
    seq.addElement(riso.distributions.Discrete.class);
    seq.addElement(riso.distributions.Discrete.class);

    helper_cache.put(
        new HelperCacheKey("lambda_message", seq),
        riso.distributions.computes_lambda_message.ConditionalDiscrete_Discrete_Discrete.class);

    seq = new Vector();
    seq.addElement(riso.distributions.ConditionalDiscrete.class);
    seq.addElement(riso.distributions.Discrete.class);

    helper_cache.put(
        new HelperCacheKey("lambda_message", seq),
        riso.distributions.computes_lambda_message.ConditionalDiscrete_Discrete_.class);

    seq = new Vector();
    seq.addElement(riso.distributions.Discrete.class);
    seq.addElement(riso.distributions.Discrete.class);

    helper_cache.put(
        new HelperCacheKey("posterior", seq),
        riso.distributions.computes_posterior.Discrete_Discrete.class);

    System.err.println("PiHelperLoader.static: helper_cache.size(): " + helper_cache.size());
  }
  /**
   * Check the helpers currently stored in the helper cache to see if any of them can handle the
   * sequence we've just been given. This avoids pinging the belief network context to get a helper
   * list.
   */
  public static Class find_helper_class1(
      Vector seq, String helper_type, int[] max_class_score, int[] max_count_score)
      throws ClassNotFoundException {
    int[] class_score1 = new int[1], count_score1 = new int[1];
    max_class_score[0] = -1;
    max_count_score[0] = -1;
    Class cmax_score = null;

    for (Enumeration e = helper_cache.keys(); e.hasMoreElements(); ) {
      try {
        HelperCacheKey key = (HelperCacheKey) e.nextElement();
        if (!key.helper_type.equals(helper_type)) continue;
        Class c = (Class) helper_cache.get(key);
        SeqTriple[] sm = (SeqTriple[]) invoke_description(c);
        if (sm == null) continue; // apparently not a helper class
        if (MatchClassPattern.matches(sm, seq, class_score1, count_score1)) {
          if (class_score1[0] > max_class_score[0]
              || (class_score1[0] == max_class_score[0] && count_score1[0] > max_count_score[0])) {
            cmax_score = c;
            max_class_score[0] = class_score1[0];
            max_count_score[0] = count_score1[0];
          }
        }
      } catch (Exception e2) {
      } // eat it; stagger forward
    }

    if (Global.debug > 1)
      System.err.println(
          "PiHelperLoader.find_helper_class1: helper "
              + (cmax_score == null ? "is NOT" : "is")
              + " in cache.");
    if (cmax_score == null) // no luck; try to get a helper list from the bnc & plunge ahead
    return find_helper_class0(seq, helper_type, max_class_score, max_count_score);
    else // success!
    return cmax_score;
  }
Exemple #9
0
 public void leaveUser(ChatUser u) throws RemoteException {
   if (userstable.containsKey(u.getName())) {
     userstable.remove(u.getName());
     broadcastLeaving(u.getName());
   }
 }
Exemple #10
0
 public void joinUser(ChatUser u) throws java.rmi.RemoteException {
   if (!userstable.containsKey(u.getName())) {
     userstable.put(u.getName(), u);
     broadcastJoining(u.getName());
   }
 }
  /**
   * This method returns a <tt>Class</tt> for a helper which can handle the list of distributions
   * specified by <tt>seq1</tt>. We maintain a cache of recently-loaded helpers, so check the cache
   * before going to the trouble of searching for a helper. The cache is blown away every
   * <tt>HELPER_CACHE_REFRESH</tt> seconds.
   *
   * <p>If we can't find a helper in the cache, we must search through the list of available helpers
   * to find an appropriate one. First try to find helper using class sequence as specified by
   * <tt>seq</tt>. Whether or not that succeeds, promote any <tt>Gaussian</tt> in the sequence to
   * <tt>MixGaussians</tt>, and try again. If we get a better match on the second try, return the
   * helper thus found.
   */
  public static Class find_helper_class(Vector seq1, String helper_type)
      throws ClassNotFoundException {
    // Let's see if an appropriate helper is in the cache.
    // If the cache is too old, empty it and search for the helper anew.

    if (System.currentTimeMillis() - cache_timestamp > HELPER_CACHE_REFRESH) {
      helper_cache = new Hashtable();
      cache_timestamp = System.currentTimeMillis();
      // Go on and search for appropriate helper.
    } else {
      HelperCacheKey key = new HelperCacheKey(helper_type, seq1);
      Class helper_class = (Class) helper_cache.get(key);
      if (helper_class != null) {
        if (Global.debug > -1)
          System.err.println(
              "PiHelperLoader.find_helper_class: found helper class: "
                  + helper_class
                  + "; no need to search.");
        return helper_class;
      }
      // else no luck; we have to search for helper.
    }

    // Well, we didn't find a helper in the cache, so let's go to work.
    if (Global.debug > -1)
      System.err.println(
          "PiHelperLoader.find_helper_class: DID NOT FIND HELPER CLASS; NOW SEARCH.");

    Class c1 = null, c2 = null;
    ClassNotFoundException cnfe1 = null, cnfe2 = null;
    int[] class_score1 = new int[1], count_score1 = new int[1];
    int[] class_score2 = new int[1], count_score2 = new int[1];

    try {
      c1 = find_helper_class1(seq1, helper_type, class_score1, count_score1);
    } catch (ClassNotFoundException e) {
      cnfe1 = e;
    } // hang on, we may need to re-throw later.

    Class gaussian_class = Class.forName("riso.distributions.Gaussian");
    MixGaussians mog = new MixGaussians(1, 1);

    Vector seq2 = new Vector(seq1.size());
    for (int i = 0; i < seq1.size(); i++)
      if (gaussian_class.isAssignableFrom((Class) seq1.elementAt(i)))
        seq2.addElement(mog.getClass());
      else seq2.addElement(seq1.elementAt(i));

    try {
      c2 = find_helper_class1(seq2, helper_type, class_score2, count_score2);
    } catch (ClassNotFoundException e) {
      cnfe2 = e;
    }

    if (cnfe1 == null && cnfe2 == null) {
      // Both matched; see which one fits better.
      // Break ties in favor of the helper for non-promoted messages.

      if (class_score1[0] >= class_score2[0]
          || (class_score1[0] == class_score2[0] && count_score1[0] >= count_score2[0])) {
        if (Global.debug > 1)
          System.err.println(
              "\taccept helper " + c1 + " for non-promoted classes instead of " + c2);
        if (Global.debug > 1)
          System.err.println(
              "\t\t"
                  + class_score1[0]
                  + ", "
                  + class_score2[0]
                  + "; "
                  + count_score1[0]
                  + ", "
                  + count_score2[0]);
        helper_cache.put(new HelperCacheKey(helper_type, seq1), c1);
        return c1;
      } else {
        if (Global.debug > 1)
          System.err.println("\taccept helper " + c2 + " for promoted classes instead of " + c1);
        if (Global.debug > 1)
          System.err.println(
              "\t\t"
                  + class_score1[0]
                  + ", "
                  + class_score2[0]
                  + "; "
                  + count_score1[0]
                  + ", "
                  + count_score2[0]);
        helper_cache.put(new HelperCacheKey(helper_type, seq1), c2);
        return c2;
      }
    } else if (cnfe1 == null && cnfe2 != null) {
      // Only the first try matched, return it.
      helper_cache.put(new HelperCacheKey(helper_type, seq1), c1);
      return c1;
    } else if (cnfe1 != null && cnfe2 == null) {
      // Only the second try matched, return it.
      helper_cache.put(new HelperCacheKey(helper_type, seq1), c2);
      return c2;
    } else {
      // Neither try matched. Re-throw the exception generated by the first try.
      throw cnfe1;
    }
  }
Exemple #12
0
  public static void main(String[] args) {
    boolean do_compile_all = false;
    String bn_name = "", x1_name = "", x2_name = "";
    Vector evidence_names = new Vector();

    for (int i = 0; i < args.length; i++) {
      if (args[i].charAt(0) != '-') continue;

      switch (args[i].charAt(1)) {
        case 'b':
          bn_name = args[++i];
          break;
        case 'a':
          do_compile_all = true;
          break;
        case 'x':
          if (args[i].charAt(2) == '1') x1_name = args[++i];
          else if (args[i].charAt(2) == '2') x2_name = args[++i];
          else System.err.println("PathAnalysis.main: " + args[i] + " -- huh???");
          break;
        case 'e':
          evidence_names.addElement(args[++i]);
          break;
        default:
          System.err.println("PathAnalysis.main: " + args[i] + " -- huh???");
      }
    }

    try {
      BeliefNetworkContext bnc = new BeliefNetworkContext(null);
      bnc.add_path("/bechtel/users10/krarti/dodier/belief-nets/assorted");
      AbstractBeliefNetwork bn = bnc.load_network(bn_name);
      Hashtable path_sets;
      Enumeration p;

      if ((p = PathAnalysis.has_directed_cycle(bn)) == null)
        System.err.println("PathAnalysis: no directed cycles found in " + bn_name);
      else {
        System.err.println("PathAnalysis.main: " + bn_name + " has a directed cycle; quit.");
        System.err.print(" cycle is: ");
        while (p.hasMoreElements()) {
          System.err.print(((AbstractVariable) p.nextElement()).get_name());
          if (p.hasMoreElements()) System.err.print(" -> ");
          else System.err.println("");
        }

        System.exit(1);
      }

      Vector evidence = new Vector();
      if (evidence_names.size() > 0) {
        for (int i = 0; i < evidence_names.size(); i++)
          evidence.addElement(bn.name_lookup((String) (evidence_names.elementAt(i))));
      }

      if (do_compile_all) {
        path_sets = PathAnalysis.compile_all_paths(bn);
      } else {
        AbstractVariable x1 = (AbstractVariable) bn.name_lookup(x1_name);
        AbstractVariable x2 = (AbstractVariable) bn.name_lookup(x2_name);
        path_sets = new Hashtable();
        PathAnalysis.compile_paths(x1, x2, path_sets);

        if (PathAnalysis.are_d_connected(x1, x2, evidence))
          System.err.print(
              x1.get_name() + " and " + x2.get_name() + " are d-connected given evidence ");
        else
          System.err.print(
              x1.get_name() + " and " + x2.get_name() + " are NOT d-connected given evidence ");

        for (int i = 0; i < evidence.size(); i++)
          System.err.print(((AbstractVariable) evidence.elementAt(i)).get_name() + " ");
        System.err.println("");
      }

      System.err.println("PathAnalysis.main: results of path finding:");

      AbstractVariable[] u = bn.get_variables();
      for (int i = 0; i < u.length; i++) {
        System.err.println(" --- paths from: " + u[i].get_name() + " ---");

        for (int j = i + 1; j < u.length; j++) {
          VariablePair vp = new VariablePair(u[i], u[j]);
          Vector path_set = (Vector) path_sets.get(vp);
          if (path_set == null) continue;

          Enumeration path_set_enum = path_set.elements();
          while (path_set_enum.hasMoreElements()) {
            AbstractVariable[] path = (AbstractVariable[]) path_set_enum.nextElement();
            System.err.print(" path: ");
            for (int k = 0; k < path.length; k++) System.err.print(path[k].get_name() + " ");
            System.err.println("");
          }
        }
      }

      System.exit(0);
    } catch (Exception e) {
      System.err.println("PathAnalysis.main:");
      e.printStackTrace();
      System.exit(1);
    }
  }