mas.agentsHempelsSofa.data.graph
Class Graph

java.lang.Object
  extended by mas.agentsHempelsSofa.data.graph.Graph

public class Graph
extends java.lang.Object

An implementation for our graph. It shall be used for all tokens to have an overview of the playing-graph. A graph knows

Author:
Hempels-Sofa

Constructor Summary
Graph()
          Creates a new empty graph.
 
Method Summary
 void add(AgentToken token)
          adds an agent to the list of tokens and to the vertex, if not already contained.
 Edge add(Edge edge)
          Adds an edge to the graph.
 Vertex add(eis.iilang.Parameter identifier)
          Adds a new node to the graph with an identifier.
 Edge add(eis.iilang.Parameter param1, eis.iilang.Parameter param2)
          Adds a new edge to the graph, whereas the edge is built by two new vertices which are created by param1 and param2.
 Vertex add(Vertex vertex)
          Adds a node to the graph, if there is no equal vertex in the graph.
 boolean contains(AgentToken token)
           
 boolean contains(Edge edge)
           
 boolean contains(Vertex vertex)
           
 boolean containsAllEdges(java.util.Collection<Edge> edges)
           
 boolean containsAllTokens(java.util.Collection<AgentToken> tokens)
           
 boolean containsAllVertices(java.util.Collection<Vertex> vertices)
           
 AdjacencyMatrix getAdjacencyMatrix()
           
 java.util.LinkedList<java.lang.String> getAllTeams()
           
 java.util.LinkedList<Vertex> getConnectedComponent()
          gets the connected component which contains the actual position.
 java.util.LinkedList<Vertex> getConnectedComponent(Vertex vertex)
          gets the connected component which contains vertex.
 Edge getEdge(Edge edge)
          Returns the edge which equals edge.
 Edge getEdge(eis.iilang.Parameter param1, eis.iilang.Parameter param2)
           
 Edge getEdge(Vertex vertex1, Vertex vertex2)
           
 java.util.LinkedList<Edge> getEdges()
           
 java.util.LinkedList<AgentToken> getEnemyTokens(java.lang.String ownTeam)
           
 int getNumberOfEdges()
           
 int getNumberOfExploredEdges()
           
 int getNumberOfExploredVertices()
           
 int getNumberOfProbedVertices()
           
 int getNumberOfSurveyedEdges()
           
 int getNumberOfVertices()
           
 Vertex getPosition()
           
 double getRatioOfExploredEdges()
           
 double getRatioOfExploredVertices()
           
 double getRatioOfProbedVertices()
           
 double getRatioOfSurveyedEdges()
           
 java.util.LinkedList<Vertex> getSurveyedConnectedComponent()
          gets the connected component which contains the actual position.
 java.util.LinkedList<Vertex> getSurveyedConnectedComponent(Vertex vertex)
          gets the connected component which contains vertex.
 AgentToken getToken(AgentToken token)
           
 java.util.LinkedList<AgentToken> getTokens()
           
 int getTotalNumberOfEdges()
           
 int getTotalNumberOfVertices()
           
 Vertex getVertex(eis.iilang.Parameter param)
           
 Vertex getVertex(java.lang.String vertexName)
           
 Vertex getVertex(Vertex vertex)
           
 Vertex[] getVertexArray()
           
 java.util.LinkedList<Vertex> getVertices()
           
 boolean isAdjacentToEnemyAgent(Vertex vertex, java.lang.String team)
           
 void moveToken(AgentToken token, Vertex targetVertex)
          moves a token to another vertex.
 void setPosition(Vertex vertex)
           
 void setProbed(Vertex vertex, int value)
           
 void setSurveyed(Edge e, int weight)
           
 void SetTotalNumberOfEdges(int number)
           
 void setVertexArray(Vertex[] vertexArray)
           
 java.util.LinkedList<apltk.interpreter.data.LogicBelief> toBeliefs()
          gets all relevant beliefs of the graph (edges, vertices and tokens).
 java.lang.String toString()
           
 void updateToken(AgentToken token)
          updates an agent token. if the token is not already in the graph, it is added.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Graph

public Graph()
Creates a new empty graph.

Method Detail

add

public Vertex add(eis.iilang.Parameter identifier)
Adds a new node to the graph with an identifier. If an equal node is already contained, false is returned.

Parameters:
identifier - The identifier of the new node.
Returns:
  • the already contained vertex,
  • the newly added vertex.

add

public Vertex add(Vertex vertex)
Adds a node to the graph, if there is no equal vertex in the graph.

Returns:
  • the already contained vertex,
  • the newly added vertex.

add

public Edge add(eis.iilang.Parameter param1,
                eis.iilang.Parameter param2)
Adds a new edge to the graph, whereas the edge is built by two new vertices which are created by param1 and param2. This also adds the vertices, if not contained already contained.

Parameters:
param1 - The identifier of the first vertex.
param2 - The identifier of the second vertex.
Returns:
  • the already contained edge,
  • the newly added edge.

add

public Edge add(Edge edge)
Adds an edge to the graph. This also adds the vertices, if not already contained.

Parameters:
edge - The edge to add.
Returns:
  • the already contained edge,
  • the newly added edge.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toBeliefs

public java.util.LinkedList<apltk.interpreter.data.LogicBelief> toBeliefs()
gets all relevant beliefs of the graph (edges, vertices and tokens).

Returns:
a linked list of all relevant beliefs

contains

public boolean contains(Edge edge)
Parameters:
edge - an edge
Returns:
  • true, if an equal edge is already on the Graph
  • false, otherwise.

contains

public boolean contains(Vertex vertex)
Parameters:
vertex - a vertex
Returns:
  • true, if an equal vertex is already on the Graph
  • false, otherwise.

contains

public boolean contains(AgentToken token)
Parameters:
token - an agent token
Returns:
  • true, if an equal token is already on the Graph
  • false, otherwise.

containsAllEdges

public boolean containsAllEdges(java.util.Collection<Edge> edges)
Parameters:
edges - some edges
Returns:
  • true, if an equal edge for all edges is already on the Graph
  • false, otherwise.

containsAllVertices

public boolean containsAllVertices(java.util.Collection<Vertex> vertices)
Parameters:
vertices - some vertices
Returns:
  • true, if an equal vertex for all vertices is already on the Graph
  • false, otherwise.

containsAllTokens

public boolean containsAllTokens(java.util.Collection<AgentToken> tokens)
Parameters:
tokens - some agent tokens
Returns:
  • true, if an equal agent for all tokens is already on the Graph
  • false, otherwise.

add

public void add(AgentToken token)
adds an agent to the list of tokens and to the vertex, if not already contained.

Parameters:
token - the token to add.

moveToken

public void moveToken(AgentToken token,
                      Vertex targetVertex)
moves a token to another vertex. If there is no equal token in the graph, a new token is added at that position.

Parameters:
token - the agent token which shall be moved.
targetVertex - the target vertex.

updateToken

public void updateToken(AgentToken token)
updates an agent token. if the token is not already in the graph, it is added. All values which are not set to null or (if it is an int value) -1, are actualized (excluded: name and team). for different constructors see AgentToken

Parameters:
token - the agent token to update.

getAdjacencyMatrix

public AdjacencyMatrix getAdjacencyMatrix()
Returns:
the adjacency matrix of this graph.

getEdge

public Edge getEdge(eis.iilang.Parameter param1,
                    eis.iilang.Parameter param2)
Parameters:
param1 - the first paramter.
param2 - the second parameter.
Returns:
the edge with the fitting vertex-paramteters.

getEdge

public Edge getEdge(Vertex vertex1,
                    Vertex vertex2)
Parameters:
vertex1 - the first vertex.
vertex2 - the second vertex.
Returns:
the edge with the fitting vertices.

getEdge

public Edge getEdge(Edge edge)
Returns the edge which equals edge.

Parameters:
edge - the edge equal to the queried edge.
Returns:
the edge fitting to the input edge.

getVertex

public Vertex getVertex(eis.iilang.Parameter param)
Parameters:
param - the parameter of the vertex.
Returns:
the vertex with the fitting parameter.

getVertex

public Vertex getVertex(Vertex vertex)
Parameters:
vertex - a vertex.
Returns:
the vertex which equals vertex.

getVertex

public Vertex getVertex(java.lang.String vertexName)
Parameters:
vertexName - the name of a vertex.
Returns:
the vertex which equals the vertex with vertexName.

getVertices

public java.util.LinkedList<Vertex> getVertices()
Returns:
A linked list of all vertices in the graph.

getEdges

public java.util.LinkedList<Edge> getEdges()
Returns:
A linked list of all edges in the graph.

setPosition

public void setPosition(Vertex vertex)
Parameters:
vertex - the vertex to set as position.

getPosition

public Vertex getPosition()
Returns:
the actual position of the agent.

getNumberOfVertices

public int getNumberOfVertices()
Returns:
the number of all explored vertices.

getNumberOfEdges

public int getNumberOfEdges()
Returns:
the number of explored edges

getConnectedComponent

public java.util.LinkedList<Vertex> getConnectedComponent(Vertex vertex)
gets the connected component which contains vertex.

Parameters:
vertex - the vertex
Returns:
the connected component.

getConnectedComponent

public java.util.LinkedList<Vertex> getConnectedComponent()
gets the connected component which contains the actual position.

Returns:
the connected component.

getSurveyedConnectedComponent

public java.util.LinkedList<Vertex> getSurveyedConnectedComponent(Vertex vertex)
gets the connected component which contains vertex.

Parameters:
vertex - the vertex
Returns:
the connected component.

getSurveyedConnectedComponent

public java.util.LinkedList<Vertex> getSurveyedConnectedComponent()
gets the connected component which contains the actual position.

Returns:
the connected component.

isAdjacentToEnemyAgent

public boolean isAdjacentToEnemyAgent(Vertex vertex,
                                      java.lang.String team)
Parameters:
vertex - the vertex
team - the team
Returns:
  • true, if an enemy agent is on an adjacent token to vertex
  • false, otherwise

getEnemyTokens

public java.util.LinkedList<AgentToken> getEnemyTokens(java.lang.String ownTeam)
Parameters:
ownTeam - the own team
Returns:
all agent tokens

getAllTeams

public java.util.LinkedList<java.lang.String> getAllTeams()
Returns:
a list of all teams which are known by this agent.

setProbed

public void setProbed(Vertex vertex,
                      int value)

setSurveyed

public void setSurveyed(Edge e,
                        int weight)

setVertexArray

public void setVertexArray(Vertex[] vertexArray)
Parameters:
vertexArray - the vertexArray to set

getVertexArray

public Vertex[] getVertexArray()
Returns:
the vertexArray

getNumberOfExploredVertices

public int getNumberOfExploredVertices()
Returns:
the number of explored edges.

getRatioOfExploredVertices

public double getRatioOfExploredVertices()
Returns:
the ratio of explored vertices.

getNumberOfProbedVertices

public int getNumberOfProbedVertices()
Returns:
the number of probed vertices.

getRatioOfProbedVertices

public double getRatioOfProbedVertices()
Returns:
the ratio of probed vertices.

getNumberOfExploredEdges

public int getNumberOfExploredEdges()
Returns:
the number of explored edges.

getRatioOfExploredEdges

public double getRatioOfExploredEdges()
Returns:
the ratio of explored edges.

getNumberOfSurveyedEdges

public int getNumberOfSurveyedEdges()
Returns:
the number of surveyed edges.

getRatioOfSurveyedEdges

public double getRatioOfSurveyedEdges()
Returns:
the ratio of surveyed edges.

getTotalNumberOfVertices

public int getTotalNumberOfVertices()
Returns:
the total number of vertices in this simulation.

getTotalNumberOfEdges

public int getTotalNumberOfEdges()
Returns:
the total number of edges in this simulation.

SetTotalNumberOfEdges

public void SetTotalNumberOfEdges(int number)
Parameters:
number - the total number of edges in this simulation.

getTokens

public java.util.LinkedList<AgentToken> getTokens()
Returns:
All the agent Tokens on the graph

getToken

public AgentToken getToken(AgentToken token)
Parameters:
token - an agent token
Returns:
a reference to the token which is already in the graph. if there is no token yet, null is returned.


Copyright © 2012. All Rights Reserved.