Changeset 13965
- Timestamp:
- 07/01/16 10:47:53 (8 years ago)
- Location:
- branches/thasling/DistributedGA
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/PeerNetworkMessageHandler.cs
r13957 r13965 29 29 30 30 31 public void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacity, intcommunicationRate) {31 public void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacity, double communicationRate) { 32 32 try { 33 33 ownInstance = new PeerInfo() { -
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/TestPeerListManager.cs
r13956 r13965 42 42 43 43 #endregion 44 45 #region IPeerListManager Members 46 47 public void Init(PeerInfo source, string contactServerUrl, double communicationRate) { 48 throw new System.NotImplementedException(); 49 } 50 51 #endregion 44 52 } 45 53 } -
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageSender.cs
r13959 r13965 29 29 bufferedMessagesWrite = new SizedConcurrentQueue<KeyValuePair<PeerInfo, byte[][]>>(); 30 30 bufferedMessagesWrite.Limit = bufferedMessagesRead.Limit; 31 timer = new Timer(1000 * 60); //each 5 minutes31 timer = new Timer(1000 * 10); //each 10 seconds 32 32 timer.Elapsed += GenerateSendingTasks; 33 33 timer.Start(); -
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfPeerListManager.cs
r13959 r13965 24 24 private IContactService heartbeatClient; 25 25 26 private int communicationRate; //how many peers are contacted by this peer in percent26 private Random rand; 27 27 28 public void Init(PeerInfo source, string contactServerUrl, int communicationRate) { 28 private double communicationRate; //how many peers are contacted by this peer in percent 29 30 public void Init(PeerInfo source, string contactServerUrl, double communicationRate) { 29 31 serverString = contactServerUrl; 30 32 this.communicationRate = communicationRate; 31 33 myself = source; 34 rand = new Random(); 35 32 36 //Init ChannelFactory and Clients 33 37 var binding = new NetTcpBinding(); … … 47 51 try { 48 52 var allPeers = client.GetPeerList(myself); //maybe timout exception... 49 var peersForMessaging = ChoosePeersForMessaging(allPeers); 50 //return peersForMessaging; 51 return allPeers; //TODO: Enable 10% list communication 53 var peersForMessaging = ChoosePeersForMessaging(ref allPeers); 54 return peersForMessaging; 52 55 } 53 56 catch { } //if maybe sending failed (because of connection lost, etc.): just ignore … … 70 73 71 74 72 private List<PeerInfo> ChoosePeersForMessaging(List<PeerInfo> allPeers) { 73 //communicate with 10% of the network 74 int noOfPeers = allPeers.Count / (100 / communicationRate); 75 List<int> indexList = GetRandomItemIndexes(noOfPeers, 0, allPeers.Count - 1); 76 List<PeerInfo> res = new List<PeerInfo>(); 77 foreach (int index in indexList) { 78 res.Add(allPeers.ElementAt(index)); 75 private List<PeerInfo> ChoosePeersForMessaging(ref List<PeerInfo> allPeers) { 76 Shuffle<PeerInfo>(allPeers); 77 int toTake = Convert.ToInt32(allPeers.Count * communicationRate) + 1; 78 if (allPeers.Count > 0 && toTake == 0) { 79 toTake = 1; 79 80 } 80 return allPeers ;81 return allPeers.Take(toTake).ToList(); ; 81 82 } 82 83 private List<int> GetRandomItemIndexes(int noOfItems, int minValue, int maxValue) { 84 List<int> res = new List<int>(); 85 Random rnd = new Random(); 86 int tmp = -1; 87 while (res.Count < noOfItems) { 88 tmp = rnd.Next(minValue, maxValue + 1); 89 if (!res.Contains(tmp)) { 90 res.Add(tmp); 91 } 83 private void Shuffle<T>(IList<T> list) { 84 int n = list.Count; 85 while (n > 1) { 86 n--; 87 int k = rand.Next(n + 1); 88 T value = list[k]; 89 list[k] = list[n]; 90 list[n] = value; 92 91 } 93 return res;94 92 } 95 93 -
branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageHandler.cs
r13956 r13965 6 6 public interface IMessageHandler { 7 7 8 void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacty, int communicationRate); //Registers at contract-server8 void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacty, double communicationRate); 9 9 10 10 void PublishDataToNetwork(byte[][] data); -
branches/thasling/DistributedGA/DistributedGA.Core/Interface/IPeerListManager.cs
r13956 r13965 6 6 public interface IPeerListManager { 7 7 8 void Init(PeerInfo source, string contactServerUrl, intcommunicationRate); //Registers own instance at the contact-server8 void Init(PeerInfo source, string contactServerUrl, double communicationRate); //Registers own instance at the contact-server 9 9 10 10 List<PeerInfo> GetPeerList(); //Recieves all peers in the network from contact-server -
branches/thasling/DistributedGA/DistributedGA.Hive/P2PMigrationAnalyzer.cs
r13960 r13965 41 41 [Item("P2PMigrationAnalyzer", "Migrates individuals using a P2P network.")] 42 42 [StorableClass] 43 public class P2PMigrationAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator {43 public class P2PMigrationAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator, IExecutable { 44 44 // state: messagehandler 45 45 private IMessageHandler h; … … 118 118 validValues.Add(new EnumValue<MigrationStrategy>(MigrationStrategy.TakeRandomReplaceRandom)); 119 119 120 Parameters.Add(new ConstrainedValueParameter<EnumValue<MigrationStrategy>>("MigrationStrategy", validValues ));120 Parameters.Add(new ConstrainedValueParameter<EnumValue<MigrationStrategy>>("MigrationStrategy", validValues, (new EnumValue<MigrationStrategy>(MigrationStrategy.TakeBestReplaceBad)))); 121 121 } 122 122 … … 172 172 using (var stream = new MemoryStream()) { 173 173 var emigrantScope = emigrantsList[ei]; 174 emigrantScope.ClearParentScopes(); 174 175 var msgScope = new Scope(); 175 176 var cloner = new Cloner(); … … 177 178 msgScope.Variables.Add((IVariable)variable.Clone(cloner)); 178 179 } 179 // emigrantScope.ClearParentScopes(); 180 msgScope.ClearParentScopes(); 181 //TODO: CLEAR EMMIGRANT SCOPES 180 182 HeuristicLab.Persistence.Default.Xml.XmlGenerator.Serialize(msgScope, stream); 181 183 message[ei] = stream.GetBuffer(); … … 228 230 229 231 public bool EnabledByDefault { get { return false; } } 232 233 #region IExecutable Members 234 235 public event EventHandler<EventArgs<Exception>> ExceptionOccurred; 236 237 public ExecutionState ExecutionState { 238 get { return ExecutionState.Prepared; } 239 } 240 241 public event EventHandler ExecutionStateChanged; 242 243 public TimeSpan ExecutionTime { 244 get { return new TimeSpan(); } 245 } 246 247 public event EventHandler ExecutionTimeChanged; 248 249 public void Pause() { 250 int i = 0; 251 } 252 253 public event EventHandler Paused; 254 255 public void Prepare() { 256 int i = 0; 257 } 258 259 public event EventHandler Prepared; 260 261 public void Start() { 262 int i = 0; 263 } 264 265 public event EventHandler Started; 266 267 public void Stop() { 268 int i = 0; 269 } 270 271 public event EventHandler Stopped; 272 273 #endregion 230 274 } 231 275 }
Note: See TracChangeset
for help on using the changeset viewer.