input
stringlengths
10
828
output
stringlengths
5
107
protected void id field key released key event evt if node selected node null node selected node set object id id field get text populate node populate edges node selected node
manages the id property
private string perceive goal node string perception if perception index of perception type 3 1 obtains the sent message int message index perception index of message perception perception substring message index 9 string message perception substring 0 perception index of if the message has the convention mark int mark index message index of if mark index 1 if this message was sent to this agent if message substring 0 mark index equals this id returns the id of the goal node return message substring mark index 3 return null
perceives a message sent by the coordinator with the goal node
private void request goal throws ioexception if this position null this connection send action type 3 message this id this position string
lets the agent ask for a goal node to the coordinator
public graph get graph return new graph graph get object id node
returns the actual graph
private void visit and go to next node throws ioexception this connection send action type 2 print visiting next node thread yield
sends messages to visit the current node then wait a little
private void choose and go to next node throws ioexception string curr node id this next node this next node grav manager get strongest neighbor curr node id sends a message to other agents this connection send action type 3 message this identifier curr node id this next node inform the gravity manager this grav manager set next node this identifier curr node id this next node go to the chosen node this connection send action type 1 node id next node
chooses the new goal node considering that the agent has arrived
private void execute next step throws ioexception if this plan is empty obtains the id of the next node string next node this plan remove sends the action to visit the current node this connection send action type 2 sends the action to go to the next node this connection send action type 1 node id next node
lets the agent execute next step of its planning
private void wait for graph boolean graph perceived false string messages print awaiting graph message while graph perceived this working thread yield messages connection retrieve messages for int i 0 i messages length i if graph perceived graph perceived perceive graph update messages i perceive broadcast of chosen node messages i print graph perceived
wait until a graph is perceived
private void wait for arrival boolean agent arrived false boolean graph perceived string messages print awaiting arrival message while agent arrived this working thread yield messages connection retrieve messages for int i 0 i messages length i agent arrived perceive arrival message messages i if agent arrived print agent arrived next node break graph perceived perceive graph update messages i if graph perceived continue perceive broadcast of chosen node messages i
waits the agent to arrive at his destiny node
private boolean perceive graph update string message try graph perceived graphs graph translator get graphs message if perceived graphs length 0 grav manager set graph perceived graphs 0 return true catch exception e e print stack trace return false
checks if the given message is the perception of a graph
public boolean equals string and double object if object null this string equals object string this double object double return true return false
compares a given string and double object to this one
private boolean perceive arrival message string message if message index of perception type 4 1 int node index message index of node id message message substring node index 9 string node id message substring 0 message index of for the start of simulation if next node null next node node id return true else if node id equals next node return true return false
checks if the given message is a perception and if it indicates
private void wait for arrival message boolean agent arrived false string messages print awaiting arrival message while agent arrived this working thread yield messages connection retrieve messages for int i 0 i messages length i print received messages i agent arrived perceive arrival message messages i if agent arrived print agent arrived goal node break else perceive graph and update black board messages i
waits the agent to arrive at his destiny node
private boolean perceive arrival message string message if message index of perception type 4 1 int node index message index of node id message message substring node index 9 string node id message substring 0 message index of for the start of simulation if goal node null goal node node id return true else if node id equals goal node return true return false
checks if the given message is a perception and if it indicates
public double get e return this e
returns the probability of an agent choose an exploration action
private int get exploration action id int state id the id of the action randomly obtained int action id int math random this actions per state count state id returns the chosen action id return action id
returns a randomly chosen action exploration action given the current
public double get gama return this gama
returns the discount factor in the q learning algorithm
public int get action id int state id boolean is learning phase if this action mode rn distribution next int 0 return this get exploration action id state id else return this get exploitation action id state id
returns the id of the action correspondent to the given state id
public int get action id int action id this q table get action id this current state id qlearning engine is learning phase this q table set use this current state id action id this last action id action id return action id 1
returns the id of the action correspondent to the current state
public void set value int state id int action id double value this values state id action id value
configures the value of the q table given the id of the correspondent
public void set possible actions count int actions count this q table set possible actions count this current state id actions count
configures the number of possible actions for the current state id
public int get use int state id int action id return this uses state id action id
returns the number of times an action was executed given a state id
public void set use int state id int action id this uses state id action id
registers that a given action was executed in a given state
public void set last action duration double duration this last action duration duration
configures the duration of the last action executed
public void set possible actions count int state id int actions count this actions per state count state id actions count
configures the number of possible actions for a given state id
public void set reward double reward this reward reward
configures the reward for the last action executed by the agent
public string to string string buffer answer new string buffer for int i 0 i this values length i for int j 0 j this values i length j answer append this values i j n for int i 0 i this uses length i for int j 0 j this uses i length j answer append this uses i j n for int i 0 i this actions per state count length i answer append this actions per state count i n return answer to string
converts the q table to a string
public void set next state int next state items values this next state id this get state id next state items values
configures the next state of the environment
public void stop working this is active false saves the q learning values into the proper file if qlearning engine is learning phase try file writer file writer new file writer this q table file path file writer print this q table to string file writer close catch ioexception e e print stack trace
makes this thread stop working
private void go to string next node id throws ioexception string message action type 1 node id next node id this connection send message
lets the agent go to the given node
protected boolean look for arrival message string messages boolean arrived false messages connection retrieve messages for int i 0 i messages length i arrived is arrival message messages i if arrived return true sync print waiting agent to arrive at node nodes next node return false
checks if a message was received informing that the agent
protected boolean is arrival message string message if message index of perception type 4 1 int node index message index of node id message message substring node index 9 string node id message substring 0 message index of if node id equals nodes next node return true return false
checks if the given message is a perception and if it indicates
protected void sync print string message if system current time millis time to print system out printf s s n identifier message time to print system current time millis print interval
prints the message in the console if the time interval since the last
protected void async print string message system out printf s s n identifier message time to print system current time millis print interval
prints the message in the console doesnt have to respect the minimum
public void add observer tcp connection observer observer this observers add observer
set the observers that will be called when receive a message
private void wait for arrival message boolean agent arrived false agent arrived look for arrival message while agent arrived this working thread yield agent arrived look for arrival message
waits the agent to arrive at his destiny node
public void update observers for int i 0 i observers size i observers get i update
update the observers when a new packet arrives
public string get remote socket adress string complete address this server socket get remote socket address to string int socket index complete address index of return complete address substring 1 socket index
returns the socket address of the remote contact in ip format
private void print string message system out println id to upper case message
print a message with the identifier of the agent
public void stop working this working false try this server output close this server input close this server socket close catch ioexception e e print stack trace
indicates that the connection must be closed
public void send string message throws ioexception this server output println message this server output flush
sends a given string message to the remote contact
public void run while this working try this receive catch ioexception e e print stack trace this working false thread yield system out println connection s thread stopped this update observers
actively receives messages from the socket and stores them
private void go to string next vertex id throws ioexception string message action type 1 node id next vertex id this connection send message
lets the agent go to the given vertex
private string perceive goal node string perception if perception index of perception type 3 1 obtains the sent message int message index perception index of message perception perception substring message index 9 string message perception substring 0 perception index of if the message has the conventional mark int mark index message index of if mark index 1 if this message was sent to this agent if message substring 0 mark index equals this id returns the id of the goal node return message substring mark index 3 return null
perceives a message sent by the coordinator with the goal node
public string read string throws ioexception string next string null string line this buffer this next token line for int i this first line i this lines count i this buffer i null this buffer 0 line this next token line 0 this first line 0 this lines count 1 int i 0 int size line length for i this next token col i size i if line char at i line char at i t break next string line substring this next token col i this next char i this find next return next string
reads a string from the file
public string read whole file throws ioexception string buffer buffer new string buffer while this is end of file buffer append this read line file reader close return buffer to string
reads the whole file removing line breaks and returns an only
public void add curve double x double y color col draw style d if x length y length system out println not the same number of doubles in the lists return curve c new curve x y col d curbs add c if c max x max x max x c max x if c min x min x min x c min x if c max y max y max y c max y if c min y min y min y c min y
add a curve to the plot
public void set xdivision int div x division div
set the x axis graduation
public boolean is valid graph graph return get cost graph 1
tests if the directed edges of the path really exist
public int get cost graph graph list integer path to vertex list int cost 0 for int i 1 i path size i if graph exists edge path get i 1 path get i system err println n o existe aresta path get i 1 path get i return 1 cost graph get length path get i 1 path get i return cost
calculates the cost of the path in the given graph
public int get xdivision return x division
get the x axis graduation
public boolean is cycle graph graph list integer list to vertex list int first list get 0 int last list get list size 1 return first last
tests if the start and end vertex of the path are the same
public void set ydivision int div y division div
set the y axis graduation
public path get path int source int destiny path path if distance source destiny infinite path new path get path internal source destiny path else path null return path
returns the path from source to destiny or null if no
public int get ydivision return y division
get the x axis graduation
public int get destiny predecessor int source int destiny return predecessor source destiny
returns the node immediately before destiny in the path from
public double get distance int source int destiny if distance source destiny infinite return integer max value else return distance source destiny
returns the minimum distance from source to destiny
public graph to distances graph int order this distance length graph graph new graph full distances order representation mixed for int v 0 v order v for int x 0 x order x if distance v x infinite graph add edge min path v x v x distance v x return graph
returns a complete graph where the edges are weighted by
private void paint point graphics g int x int y curve c if c get point style draw style none c get point style draw style point plus g draw line x 5 y x 5 y g draw line x y 5 x y 5 else if c get point style draw style point cross g draw line x 5 y 5 x 5 y 5 g draw line x 5 y 5 x 5 y 5 else g fill oval x 3 y 3 6 6
paints the point int the style choosed for the curve c
public void disconnect this source remove edge this this target remove edge this
disconnects the edge updating the source and target references
public edge get copy node copy source node copy target registers if the original edge is directed boolean directed this source is collector of this the copy edge copy edge new edge copy source copy target directed this length copy edge id this id returns the answer return copy edge
obtains a copy of the edge with the given copies of nodes
public boolean is smaller than comparable object if object instanceof edge if this length edge object length return true return false
compares a given edge to this one based on their lengths
public int add node int n all nodes size all nodes add new node node n return n
adds a new node and returns a positive integer identifying it
public void add edge int source int target double weight node source node all nodes get source node target node all nodes get target attention the edge adds itself to the nodes edge edge new edge source node target node directed edges weight edge set object id edge source target
adds an edge from source node to target node with a cost given
public int get num nodes return all nodes size
returns the current number of nodes
public graph to graph string name node ns new node all nodes size all nodes to array ns return new graph name ns
converts this object to an object of graph class
public void remove edge edge edge if this in edges null this in edges remove edge if this out edges null this out edges remove edge
removes a given edge from the node
public int get degree int answer 0 if this in edges null answer this in edges size if this out edges null if this in edges null answer this out edges size else for edge edge this out edges if this in edges contains edge answer return answer
returns the degree of the node
public boolean has node node node for node current node this nodes if current node equals node return true return false
verifies if the given node is part of the graph
public void stop working try this stop working true this connection stop working catch ioexception e e print stack trace
indicates that the client must stop working
public graph generate undirected int num vertices int min degree int max degree return generate undirected num vertices min degree max degree 1 1
generates a random graph with undirected edges and with the given number of
public void set idleness double idleness this idleness idleness
configures the idleness of the node
public double get idleness return this idleness
returns the idleness of the node
public graph generate complete int num vertices return generate complete num vertices 1 1
generates a random complete graph i
public graph generate complete int num vertices int min weight int max weight graph builder graph new graph builder num vertices false int capacity for int v 0 v num vertices v for int x v 1 x num vertices x capacity int random min weight max weight graph add edge v x capacity return graph to graph random complete
generates a random complete graph i
public boolean has edge edge edge if this edges null for edge current edge this edges if current edge equals edge return true return false
verifies if the given edge is part of the graph
public void erase priority field string current map copy this current map this current map int next index current map copy index of priority while next index 1 this current map current map copy substring 0 next index current map copy current map copy substring next index 10 current map copy current map copy substring current map copy index of 2 next index current map copy index of priority this current map current map copy
erases the priority field
private void configure start throws ioexception waits for the user to press any key to start simulation system out print press enter to start simulation keyboard read line the message to be sent to the server string message configuration type 3 parameter this time of simulation send the message to the server this connection send message screen message system out println simulation started
configures the server to start the simulation with the given time of
private void stop agents if this agents null for agent agent this agents agent stop working
stops the agents
public double get max interval return all intervals max
maximum interval between consecutive visits considering all
public void set connection client connection connection this connection connection
configures the connection of the agent
public double get average interval return all intervals mean
average interval between consecutive visits considering all
public double get std dev of intervals return all intervals standard deviation
standard deviation of the intervals between consecutive visits
public double get quadratic mean of intervals return all intervals generalized mean 2 0d this all weights
quadratic mean of the intervals between consecutive visits
public double get generalized mean of intervals double p return all intervals generalized mean p this all weights
generalized mean of the intervals between consecutive visits
public double get max instantaeous idleness return get max interval
maximum instantaneous idleness of all nodes in all time instants
public double get average idleness return nodes idlenesses mean
average idlenesses along the simulation averaged by the number of nodes
public double get total visits return nodes visits count sum
total number of visits considering all nodes
public double get average visits return nodes visits count mean
average number of visits per node
public double get std dev visits return nodes visits count standard deviation
standard deviation of the numbers of visits per node
public boolean equals graph graph if graph null if graph label equals this label return false node nodes graph get nodees for int i 0 i nodes length i node node this get node nodes i get object id if node null node get idleness nodes i get idleness return false edge edges graph get edges for int i 0 i edges length i edge edge this get edge edges i get object id if edge null return false return true return false
compares a given graph to this one
public double get exploration time boolean explored new boolean num nodes all false initially int num vis 0 visit visit boolean test true while num vis visits get num visits visit visits get visit num vis if explored visit vertex explored visit vertex true test true for boolean exp explored test exp if test return visit time num vis return 1
exploration time time at which each node has been visited at least once
public double get norm exploration time int num agents double exp time get exploration time if exp time 1 return 1 return exp time num agents num nodes
normalized exploration time exp time nb agents nb nodes
public boolean engine can resolve attr uri string base uri string uri node value uri get node value if uri node value equals uri node value starts with return false try uri uri new new uri new uri base uri uri get node value if uri new get scheme equals http return true catch uri malformed uriexception ex return false
we resolve http uris i without i fragment
public signed document create signature document return new signed document
create an instance of
public dnie document to sign create dnie document to sign return new dnie document to sign
create an instance of
public dnie document to sign option create dnie document to sign option return new dnie document to sign option
create an instance of
public dnie signed document option selected create dnie signed document option selected return new dnie signed document option selected
create an instance of
override protected void startup runtime data get instance client view new dnie gp2 pclient view this show client view dimension screen size toolkit get default toolkit get screen size client view get frame set size screen size width screen size height
at startup create and show the main frame of the application
public dnie signed document create dnie signed document return new dnie signed document
create an instance of