Permalink
Browse files

Merging Projects2

  • Loading branch information...
Collin Johnston Collin Johnston
Collin Johnston authored and Collin Johnston committed Apr 2, 2012
1 parent 43a979b commit e52cf6b0aa2c7a2f6235edd9902a1543ab64c435
Showing with 1,928 additions and 0 deletions.
  1. +7 −0 Robin/.classpath
  2. +33 −0 Robin/.project
  3. +31 −0 Robin/AndroidManifest.xml
  4. 0 Robin/README
  5. +17 −0 Robin/Simulation/Client.py
  6. +128 −0 Robin/Simulation/Graph.py
  7. BIN Robin/Simulation/Graph.pyc
  8. +123 −0 Robin/Simulation/Graph.py~
  9. +139 −0 Robin/Simulation/Node.py
  10. BIN Robin/Simulation/Node.pyc
  11. +139 −0 Robin/Simulation/Node.py~
  12. +21 −0 Robin/Simulation/Path.py
  13. BIN Robin/Simulation/Path.pyc
  14. +55 −0 Robin/Simulation/Server.py
  15. +94 −0 Robin/Simulation/ucb.py
  16. BIN Robin/Simulation/ucb.pyc
  17. BIN Robin/bin/Robin.apk
  18. BIN Robin/bin/classes.dex
  19. BIN Robin/bin/com/Robin/proto/ChangeRequest.class
  20. BIN Robin/bin/com/Robin/proto/MessageManager$1.class
  21. BIN Robin/bin/com/Robin/proto/MessageManager$2$1.class
  22. BIN Robin/bin/com/Robin/proto/MessageManager$2$2.class
  23. BIN Robin/bin/com/Robin/proto/MessageManager$2.class
  24. BIN Robin/bin/com/Robin/proto/MessageManager.class
  25. BIN Robin/bin/com/Robin/proto/MessageTypes.class
  26. BIN Robin/bin/com/Robin/proto/PendingBuffer.class
  27. BIN Robin/bin/com/Robin/proto/R$attr.class
  28. BIN Robin/bin/com/Robin/proto/R$drawable.class
  29. BIN Robin/bin/com/Robin/proto/R$id.class
  30. BIN Robin/bin/com/Robin/proto/R$layout.class
  31. BIN Robin/bin/com/Robin/proto/R$string.class
  32. BIN Robin/bin/com/Robin/proto/R.class
  33. BIN Robin/bin/com/Robin/proto/RobinActivity$1.class
  34. BIN Robin/bin/com/Robin/proto/RobinActivity.class
  35. BIN Robin/bin/com/Robin/proto/SelectorIOManager$1.class
  36. BIN Robin/bin/com/Robin/proto/SelectorIOManager$2.class
  37. BIN Robin/bin/com/Robin/proto/SelectorIOManager.class
  38. BIN Robin/bin/com/Robin/proto/UDPAnnouncementManager$1.class
  39. BIN Robin/bin/com/Robin/proto/UDPAnnouncementManager$2.class
  40. BIN Robin/bin/com/Robin/proto/UDPAnnouncementManager.class
  41. BIN Robin/bin/com/Robin/proto/UserMessage.class
  42. BIN Robin/bin/resources.ap_
  43. +11 −0 Robin/default.properties
  44. +40 −0 Robin/gen/com/Robin/proto/R.java
  45. +40 −0 Robin/proguard.cfg
  46. BIN Robin/res/drawable-hdpi/icon.png
  47. BIN Robin/res/drawable-ldpi/icon.png
  48. BIN Robin/res/drawable-mdpi/icon.png
  49. +84 −0 Robin/res/layout/main.xml
  50. +5 −0 Robin/res/values/strings.xml
  51. +18 −0 Robin/src/com/Robin/proto/ChangeRequest.java
  52. +227 −0 Robin/src/com/Robin/proto/MessageManager.java
  53. +5 −0 Robin/src/com/Robin/proto/MessageTypes.java
  54. +90 −0 Robin/src/com/Robin/proto/PendingBuffer.java
  55. +80 −0 Robin/src/com/Robin/proto/RobinActivity.java
  56. +312 −0 Robin/src/com/Robin/proto/SelectorIOManager.java
  57. +141 −0 Robin/src/com/Robin/proto/UDPAnnouncementManager.java
  58. +88 −0 Robin/src/com/Robin/proto/UserMessage.java
View
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Robin</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.Robin.proto"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
+
+ <uses-permission android:name="android.permission.INTERNET"/>
+
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+
+
+ <uses-sdk android:minSdkVersion="8" />
+
+ <application
+ android:label="@string/app_name" android:debuggable="true" >
+ <activity
+ android:label="@string/app_name"
+ android:name=".RobinActivity" >
+ <intent-filter >
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
View
No changes.
View
@@ -0,0 +1,17 @@
+import socket
+import sys
+
+HOST,PORT = "localhost", 9999
+data = ' '.join(sys.argv[1:])
+
+sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+
+try:
+ sock.connect((HOST, PORT))
+ sock.sendall(data+"\n")
+
+ received = sock.recv(1024)
+finally:
+ sock.close()
+print "Sent: {}".format(data)
+print"Received: {}".format(received)
View
@@ -0,0 +1,128 @@
+import pygraphviz as pgv
+from ucb import interact
+
+class Graph:
+ def __init__(self, *nodes):
+ self.nodes = list(nodes)
+ self.G = pgv.AGraph(resolution="75", overlap='scale', splines="True")
+
+ def __iter__(self):
+ return self.nodes.__iter__()
+
+ def __repr__(self):
+ string = ""
+ for node in self:
+ string += str(node) + '\n'
+ return string
+
+ def summary2(self, this_node):
+ max_edges = 0
+ shortest_path_dict = dict() #Key = Node.id : Value = len(shortest path from HOST to KEY)
+ out_edges_dict = dict() #Key = Node.id : Value = list of nodes that are outward from it
+ votes_dict = dict() #Key = Node.id : Value = number of votes they have.
+
+ for node in self: # This builds the shortest_path_dict by the length each node is away from the HOST node
+ if this_node.id != node.id:
+ path = this_node.shortestPathTo(node)
+
+ if path is not None:
+ shortest_path_dict[node.id] = len(path)
+ else:
+ shortest_path_dict[node.id] = 0
+ for node in self: #Builds the out_edges_dict by calculating how many connecting nodes are at least as far away from host as this node
+ if this_node.id != node.id: #Don't look at host node
+ for edge_node_id in node.trusts: #check each node connected to this one
+ if edge_node_id != this_node.id:
+ if shortest_path_dict[edge_node_id] > shortest_path_dict[node.id]: #if they are farther away from host than we are, we give them some votes
+ if node.id in out_edges_dict: #add ourself to the list of nodes that are outward from the node we are looking at
+ out_edges_dict[node.id] += [edge_node_id]
+ else:
+ out_edges_dict[node.id] = [edge_node_id]
+ max_edges = len(max(out_edges_dict.values(), key=len)) #unused now
+ const_vote_percent = .1 #percent of votes it gives to each ouward edge <------THIS IS SOMETHING YOU CAN CHANGE
+ queue = [] #BF distribution of votes
+ for edge_id in this_node.trusts: #Populate the immediate friends vote counts
+ votes_dict[edge_id] = 100/len(this_node.trusts)
+ queue.append(edge_id)
+ while len(queue) != 0:
+ const_vote_percent = .1
+ node_id = queue.pop(0)
+ if node_id in out_edges_dict:
+ num_nodes = len(out_edges_dict[node_id])
+ if num_nodes * const_vote_percent > .7: # <----- CHANGE THIS .5
+ const_vote_percent = .7/num_nodes # <------ AND THIS .5 TO THE SAME NUMBER
+ for edge_node_id in out_edges_dict[node_id]:
+ if edge_node_id == this_node.id:
+ continue
+ votes_dict[edge_node_id] = const_vote_percent * votes_dict[node_id]
+ queue.append(edge_node_id)
+ votes_dict[node_id] -= const_vote_percent * votes_dict[node_id]*len(out_edges_dict[node_id])
+ print(str(out_edges_dict))
+ return votes_dict
+
+
+
+ def summary(self, this_node):
+ total_unique_paths = 0
+ unique_paths_by_node = {} # <- Collin can't name things. This is
+ # node.id: list of path lengths
+ real_unique_paths_by_node = {}
+ for node in self:
+ if node != this_node:
+ paths = this_node.pathsTo(node)
+ real_unique_paths_by_node[node.id] = paths
+ unique_paths_by_node[node.id] = [len(path) for path in paths]
+ total_unique_paths += sum(unique_paths_by_node[node.id])
+## print(unique_paths_by_node)
+## print(total_unique_paths)
+ summary = dict((node, sum([(total_unique_paths*1.0)/i for i in unique_paths_by_node[node]])) for (node) in unique_paths_by_node.keys())
+ max_trust = max(summary.values())
+ summary = dict((node, (summary[node]*1.0)/max_trust) for (node) in unique_paths_by_node.keys())
+ newSum = {}
+ for nodeId in real_unique_paths_by_node.keys():
+ Paths = real_unique_paths_by_node[nodeId]
+ print("Paths: ", Paths)
+ if Paths == []:
+ continue
+ pathNodes = real_unique_paths_by_node[nodeId][0].getNodes()
+ print("This node: ", this_node.id)
+ print("Path Nodes: ", pathNodes)
+ print("Summary Keys: ", summary.keys())
+ invertedPathNodePhase1TrustValues = []
+ for path_node in pathNodes:
+ if (path_node.id != this_node.id):
+ invertedPathNodePhase1TrustValues.append(summary[path_node.id]**(-1))
+ newSum[nodeId] = sum(invertedPathNodePhase1TrustValues)
+## for node in summary.keys():
+## print(str(node) + " : " + str(summary[node]))
+ return newSum
+
+ def drawMe(self, this_node=None):
+ if this_node is not None:
+ summary = self.summary2(this_node)
+ for node in self.nodes:
+ for trust in node.trusts:
+ if this_node == None:
+ self.G.add_edge(node.id, trust)
+ elif node.id == this_node.id:
+ self.G.add_edge(this_node.id, str(trust) + ":" + str(round(summary[trust], 6)))
+ elif this_node.id == trust:
+ self.G.add_edge(this_node.id, str(node.id) + ":" + str(round(summary[node.id], 6)))
+ else:
+ self.G.add_edge(str(node.id) + ":" + str(round(summary[node.id], 6)), str(trust) + ":" + str(round(summary[trust], 6)))
+ else:
+ for node in self.nodes:
+ for trust in node.trusts:
+ if trust is not node.id:
+ self.G.add_edge(node.id, trust)
+ print("Creating graf")
+ self.G.layout(prog='dot')
+ self.G.draw('graph.png')
+
+ def printSummary(self, node):
+ summary = self.summary(node)
+ for node in summary.keys():
+ print(str(node) + " : " + str(summary[node]))
+
+ def add(self, node):
+ self.nodes.append(node)
View
Binary file not shown.
View
@@ -0,0 +1,123 @@
+import pygraphviz as pgv
+from ucb import interact
+
+class Graph:
+ def __init__(self, *nodes):
+ self.nodes = list(nodes)
+ self.G = pgv.AGraph(resolution="75", overlap='scale', splines="True")
+
+ def __iter__(self):
+ return self.nodes.__iter__()
+
+ def __repr__(self):
+ string = ""
+ for node in self:
+ string += str(node) + '\n'
+ return string
+
+ def summary2(self, this_node):
+ max_edges = 0
+ shortest_path_dict = dict() #Key = Node.id : Value = len(shortest path from HOST to KEY)
+ out_edges_dict = dict() #Key = Node.id : Value = list of nodes that are outward from it
+ votes_dict = dict() #Key = Node.id : Value = number of votes they have.
+
+ for node in self: # This builds the shortest_path_dict by the length each node is away from the HOST node
+ if this_node.id != node.id:
+ path = this_node.shortestPathTo(node)
+
+ if path is not None:
+ shortest_path_dict[node.id] = len(path)
+ else:
+ shortest_path_dict[node.id] = 0
+ for node in self: #Builds the out_edges_dict by calculating how many connecting nodes are at least as far away from host as this node
+ if this_node.id != node.id: #Don't look at host node
+ for edge_node_id in node.trusts: #check each node connected to this one
+ if edge_node_id != this_node.id:
+ if shortest_path_dict[edge_node_id] > shortest_path_dict[node.id]: #if they are farther away from host than we are, we give them some votes
+ if node.id in out_edges_dict: #add ourself to the list of nodes that are outward from the node we are looking at
+ out_edges_dict[node.id] += [edge_node_id]
+ else:
+ out_edges_dict[node.id] = [edge_node_id]
+ max_edges = len(max(out_edges_dict.values(), key=len)) #unused now
+ const_vote_percent = .1 #percent of votes it gives to each ouward edge <------THIS IS SOMETHING YOU CAN CHANGE
+ queue = [] #BF distribution of votes
+ for edge_id in this_node.trusts: #Populate the immediate friends vote counts
+ votes_dict[edge_id] = 100/len(this_node.trusts)
+ queue.append(edge_id)
+ while len(queue) != 0:
+ const_vote_percent = .1
+ node_id = queue.pop(0)
+ if node_id in out_edges_dict:
+ num_nodes = len(out_edges_dict[node_id])
+ if num_nodes * const_vote_percent > .5: # <----- CHANGE THIS .5
+ const_vote_percent = .5/num_nodes # <------ AND THIS .5 TO THE SAME NUMBER
+ for edge_node_id in out_edges_dict[node_id]:
+ if edge_node_id == this_node.id:
+ continue
+ votes_dict[edge_node_id] = const_vote_percent * votes_dict[node_id]
+ queue.append(edge_node_id)
+ votes_dict[node_id] -= const_vote_percent * votes_dict[node_id]*len(out_edges_dict[node_id])
+ print(str(out_edges_dict))
+ return votes_dict
+
+
+
+ def summary(self, this_node):
+ total_unique_paths = 0
+ unique_paths_by_node = {} # <- Collin can't name things. This is
+ # node.id: list of path lengths
+ real_unique_paths_by_node = {}
+ for node in self:
+ if node != this_node:
+ paths = this_node.pathsTo(node)
+ real_unique_paths_by_node[node.id] = paths
+ unique_paths_by_node[node.id] = [len(path) for path in paths]
+ total_unique_paths += sum(unique_paths_by_node[node.id])
+## print(unique_paths_by_node)
+## print(total_unique_paths)
+ summary = dict((node, sum([(total_unique_paths*1.0)/i for i in unique_paths_by_node[node]])) for (node) in unique_paths_by_node.keys())
+ max_trust = max(summary.values())
+ summary = dict((node, (summary[node]*1.0)/max_trust) for (node) in unique_paths_by_node.keys())
+ newSum = {}
+ for nodeId in real_unique_paths_by_node.keys():
+ Paths = real_unique_paths_by_node[nodeId]
+ print("Paths: ", Paths)
+ if Paths == []:
+ continue
+ pathNodes = real_unique_paths_by_node[nodeId][0].getNodes()
+ print("This node: ", this_node.id)
+ print("Path Nodes: ", pathNodes)
+ print("Summary Keys: ", summary.keys())
+ invertedPathNodePhase1TrustValues = []
+ for path_node in pathNodes:
+ if (path_node.id != this_node.id):
+ invertedPathNodePhase1TrustValues.append(summary[path_node.id]**(-1))
+ newSum[nodeId] = sum(invertedPathNodePhase1TrustValues)
+## for node in summary.keys():
+## print(str(node) + " : " + str(summary[node]))
+ return newSum
+
+ def drawMe(self, this_node=None):
+ if this_node is not None:
+ summary = self.summary2(this_node)
+ for node in self.nodes:
+ for trust in node.trusts:
+ if this_node == None:
+ self.G.add_edge(node.id, trust)
+ elif node.id == this_node.id:
+ self.G.add_edge(this_node.id, str(trust) + ":" + str(round(summary[trust], 6)))
+ elif this_node.id == trust:
+ self.G.add_edge(this_node.id, str(node.id) + ":" + str(round(summary[node.id], 6)))
+ else:
+ self.G.add_edge(str(node.id) + ":" + str(round(summary[node.id], 6)), str(trust) + ":" + str(round(summary[trust], 6)))
+ print("Creating graf")
+ self.G.layout(prog='dot')
+ self.G.draw('graph.png')
+
+ def printSummary(self, node):
+ summary = self.summary(node)
+ for node in summary.keys():
+ print(str(node) + " : " + str(summary[node]))
+
+ def add(self, node):
+ self.nodes.append(node)
Oops, something went wrong.

0 comments on commit e52cf6b

Please sign in to comment.