Package cu.repsystestbed.exceptions

Examples of cu.repsystestbed.exceptions.GenericTestbedException


        Instance temp = (Instance)enu.nextElement();
        logger.info("Parsing " + temp);
        String[] feedbackInstance = new String[3];
        //go through each feedback line
       
        if(temp.numValues()!=3) throw new GenericTestbedException("Reputation line does not have 3 elements. This is illegal.");
       
        for(int i=0;i<temp.numValues();i++)
        {
          //number of values == 3
          feedbackInstance[i] = temp.stringValue(i);         
        }
        Agent src = new Agent(new Integer(feedbackInstance[0]));
        Agent sink = new Agent(new Integer(feedbackInstance[1]));
        Double reputation = new Double(feedbackInstance[2]);
       
        if(!repGraph.containsVertex(src))
        {
          repGraph.addVertex(src);
        }
       
        if(!repGraph.containsVertex(sink))
        {
          repGraph.addVertex(sink);
        }
       
        repGraph.addEdge(src, sink);
        ReputationEdge repEdge = (ReputationEdge) repGraph.getEdge(src, sink);
        repEdge.setReputation(reputation);
        System.out.println(repGraph);
      }
     
      return repGraph;

    } catch (Exception e)
    {
      logger.error("Error parsing arff file '" + arffFileName +"'.");
      logger.error(e);
      throw new GenericTestbedException("Error parsing arff file.", e);
    }
   
   
   
  }
View Full Code Here


  }
 
  @Override
  public Graph getGraph2Output() throws Exception
  {
    if(this.m_graph2Output.edgeSet().size()<1) throw new GenericTestbedException("No edges in reputation graph.");
    return (ReputationGraph) m_graph2Output;
  }
View Full Code Here

    {
      Util.assertNotNull(m_graph2Listen);
    }
    catch(Exception e)
    {
      throw new GenericTestbedException("Call setGraph2Listen() first.", e);
    }
    //initialize the reputation graph
    if(outputGraphType == OutputGraphType.COMPLETE_GRAPH)
    {
      /*
       * For every src and sink in the input graph, create an edge in the output graph
       */
      Graph graphTransitive = ((Graph)this.m_graph2Listen).getTransitiveClosureGraph();
      for(Agent src: (Set<Agent>) graphTransitive.vertexSet())
      {
        for(Agent sink: (Set<Agent>) graphTransitive.vertexSet())
        {
          if(!src.equals(sink))
          {
            m_graph2Output.addVertex(src);
            m_graph2Output.addVertex(sink);
            m_graph2Output.addEdge(src, sink);
          }
         
        }
      }
    }
    else if(outputGraphType == OutputGraphType.TRANSITIVE_GRAPH)
    {
      /*
       * Find the transitive closure edges of the input graph and add them to the output grph
       */
      Graph graphTransitive = ((Graph)this.m_graph2Listen).getTransitiveClosureGraph();
      for(TestbedEdge edge : (Set<TestbedEdge>)graphTransitive.edgeSet())
      {
        Agent src = (Agent)edge.src;
        Agent sink = (Agent)edge.sink;
        m_graph2Output.addVertex(src);
        m_graph2Output.addVertex(sink);
        m_graph2Output.addEdge(src, sink);
      }
    }
    else if(outputGraphType == OutputGraphType.COPY_INPUT_GRAPH)
    {
      /*
       * Copy the edges in the input graph to the output graph
       */
      Set<TestbedEdge> edges = ((Graph)this.m_graph2Listen).edgeSet();
      for(TestbedEdge edge : edges)
      {
        Agent src = (Agent)edge.src;
        Agent sink = (Agent)edge.sink;
        m_graph2Output.addVertex(src);
        m_graph2Output.addVertex(sink);
        m_graph2Output.addEdge(src, sink);
      }
    }
    else
    {
      throw new GenericTestbedException("Unknown OutputGraphType.");
    }
  }
View Full Code Here

            double trustScore = calculateTrustScore(src, sink);
            //TODO - move this to preconditions and postconditions
            //ensure the trust score is in [0,1].
            if(!assertVariablePrecondition(trustScore))
            {
              throw new GenericTestbedException("Failed postconditions: assertVariablePrecondition()");
            }
           
            if(m_graph2Output.getEdge(src, sink) != null &&
                !(m_graph2Output.getEdge(src, sink) instanceof ReputationEdge))
            {
              throw new GenericTestbedException("Expected edge type is ReputationEdge.");
            }
           
            ReputationEdge repEdge = (ReputationEdge) m_graph2Output.getEdge(src, sink);
           
            //repEdge may be null. all edges in the graph this alg listens to may have been added but that is not
            //reflected in the reputation graph edge. So reputationGraph.getEdge(src, sink) may return null.
           
            if(repEdge==null)
            {
              if(!m_graph2Output.containsVertex(src)) m_graph2Output.addVertex(src);
              if(!m_graph2Output.containsVertex(sink)) m_graph2Output.addVertex(sink);
              m_graph2Output.addEdge(src, sink)
              repEdge = (ReputationEdge) m_graph2Output.getEdge(src, sink)
            }
           
            repEdge.setReputation(trustScore);
            m_graph2Output.setEdgeWeight(repEdge, trustScore);
            edgesTobeUpdated.add(repEdge);
          }
        }
      }
    }else if(outputGraphType == OutputGraphType.TRANSITIVE_GRAPH)
    {
     
      /**
       * Calculate trust scores of sink agents that are reachable from the source.
       * that is determine the transitive closure of the graph that this alg listens to
       * and set the weights of the edges.
       */
     
      Graph transitiveGraph = m_graph2Listen.getTransitiveClosureGraph();
      
      for(Agent src : agents)
      {
        Set<TestbedEdge> outgoingEdges = transitiveGraph.outgoingEdgesOf(src);
        for(TestbedEdge e : outgoingEdges)
        {
          double trustScore = calculateTrustScore(src, (Agent)e.sink);
          if(!assertVariablePrecondition(trustScore))
          {
            throw new GenericTestbedException("Failed postconditions: assertVariablePrecondition()");
          }
         
          if(!((ReputationEdge) m_graph2Output.getEdge(src, (Agent)e.sink) instanceof ReputationEdge))
          {
            throw new GenericTestbedException("Expected edge type is ReputationEdge.");
          }
         
          ReputationEdge repEdge = (ReputationEdge) m_graph2Output.getEdge(src, (Agent)e.sink);
         
          //repEdge may be null. see setFeedbackHistoryGraph(). a feedback history graph edge may have been added but that is not
          //reflected in the reputation graph edge. So reputationGraph.getEdge(src, sink) may return null.
         
          if(repEdge==null)
          {
            if(!m_graph2Output.containsVertex(src)) m_graph2Output.addVertex(src);
            if(!m_graph2Output.containsVertex((Agent)e.sink)) m_graph2Output.addVertex((Agent)e.sink);
            m_graph2Output.addEdge(src, (Agent)e.sink);
            repEdge = (ReputationEdge) m_graph2Output.getEdge(src, (Agent)e.sink);
            repEdge.setReputation(trustScore);
          }
          m_graph2Output.setEdgeWeight(repEdge, trustScore);
          edgesTobeUpdated.add(repEdge);
         
        }
      }
    }
    else
    {
      for(Agent src : agents)
      {
        Set<TestbedEdge> outgoingEdges = super.m_graph2Listen.outgoingEdgesOf(src);
        for(TestbedEdge e : outgoingEdges)
        {
          double trustScore = calculateTrustScore(src, (Agent)e.sink);
          if(!assertVariablePrecondition(trustScore))
          {
            throw new GenericTestbedException("Failed postconditions: assertVariablePrecondition()");
          }
         
          if(!((ReputationEdge) m_graph2Output.getEdge(src, (Agent)e.sink) instanceof ReputationEdge))
          {
            throw new GenericTestbedException("Expected edge type is ReputationEdge.");
          }
         
          ReputationEdge repEdge = (ReputationEdge) m_graph2Output.getEdge(src, (Agent)e.sink);
         
          if(repEdge==null)
View Full Code Here

      algorithm = (TrustAlgorithm) cls.newInstance();
    }catch(Exception e)
    {
      String msg = "Error loading trust algorithm with name " + className;
      logger.error(msg);
      throw new GenericTestbedException(msg, e);

    }
    return algorithm;
   
  }
View Full Code Here

    {
      Util.assertNotNull(m_graph2Listen);
    }
    catch(Exception e)
    {
      throw new GenericTestbedException("Call setGraph2Listen() first.", e);
    }
   
    m_graph2Output = new TrustGraph(new TrustEdgeFactory());
    //an edge in the trust graph means src trusts sink. So don't copy the edges from the rep graph. just copy the agents
    for(Agent agent : (Set<Agent>) m_graph2Listen.vertexSet())
View Full Code Here

     
    }catch(Exception e)
    {
      String msg = "Error loading reputation algorithm with name " + className;
      logger.error(msg);
      throw new GenericTestbedException(msg, e);
    }
    return algorithm;
   
  }
View Full Code Here

        Instance temp = (Instance)enu.nextElement();
        logger.info("Parsing " + temp);
        String[] feedbackInstance = new String[3];
        //go through each feedback line
       
        if(temp.numValues()!=2) throw new GenericTestbedException("Trust line does not have 2 elements. This is illegal.");
       
        for(int i=0;i<temp.numValues();i++)
        {
          //number of values == 2
          feedbackInstance[i] = temp.stringValue(i);         
        }
        Agent src = new Agent(new Integer(feedbackInstance[0]));
        Agent sink = new Agent(new Integer(feedbackInstance[1]));
       
        if(!trustGraph.containsVertex(src))
        {
          trustGraph.addVertex(src);
        }
       
        if(!trustGraph.containsVertex(sink))
        {
          trustGraph.addVertex(sink);
        }
       
        trustGraph.addEdge(src, sink);
       
      }

    } catch (Exception e)
    {
      logger.info("Error parsing arff file '" + arffFileName +"'.");
      logger.info(e.getStackTrace());
      throw new GenericTestbedException("Error parsing arff file.", e);
    }
   
    return trustGraph;
   
  }
View Full Code Here

TOP

Related Classes of cu.repsystestbed.exceptions.GenericTestbedException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.