Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13965


Ignore:
Timestamp:
07/01/16 10:47:53 (8 years ago)
Author:
thasling
Message:

#2615:
made minor changes

Location:
branches/thasling/DistributedGA
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/PeerNetworkMessageHandler.cs

    r13957 r13965  
    2929
    3030
    31     public void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacity, int communicationRate) {
     31    public void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacity, double communicationRate) {
    3232      try {
    3333        ownInstance = new PeerInfo() {
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/TestPeerListManager.cs

    r13956 r13965  
    4242
    4343        #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
    4452    }
    4553}
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageSender.cs

    r13959 r13965  
    2929      bufferedMessagesWrite = new SizedConcurrentQueue<KeyValuePair<PeerInfo, byte[][]>>();
    3030      bufferedMessagesWrite.Limit = bufferedMessagesRead.Limit;
    31       timer = new Timer(1000 * 60); //each 5 minutes
     31      timer = new Timer(1000 * 10); //each 10 seconds
    3232      timer.Elapsed += GenerateSendingTasks;
    3333      timer.Start();
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfPeerListManager.cs

    r13959 r13965  
    2424    private IContactService heartbeatClient;
    2525
    26     private int communicationRate; //how many peers are contacted by this peer in percent
     26    private Random rand;
    2727
    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) {
    2931      serverString = contactServerUrl;
    3032      this.communicationRate = communicationRate;
    3133      myself = source;
     34      rand = new Random();
     35     
    3236      //Init ChannelFactory and Clients
    3337      var binding = new NetTcpBinding();
     
    4751      try {
    4852        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;
    5255      }
    5356      catch { } //if maybe sending failed (because of connection lost, etc.): just ignore
     
    7073
    7174
    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;
    7980      }
    80       return allPeers;
     81      return allPeers.Take(toTake).ToList(); ;
    8182    }
    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;
    9291      }
    93       return res;
    9492    }
    9593
  • branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageHandler.cs

    r13956 r13965  
    66  public interface IMessageHandler {
    77
    8     void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacty, int communicationRate); //Registers at contract-server
     8    void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacty, double communicationRate);
    99
    1010    void PublishDataToNetwork(byte[][] data);
  • branches/thasling/DistributedGA/DistributedGA.Core/Interface/IPeerListManager.cs

    r13956 r13965  
    66  public interface IPeerListManager {
    77
    8     void Init(PeerInfo source, string contactServerUrl, int communicationRate); //Registers own instance at the contact-server
     8    void Init(PeerInfo source, string contactServerUrl, double communicationRate); //Registers own instance at the contact-server
    99
    1010    List<PeerInfo> GetPeerList(); //Recieves all peers in the network from contact-server
  • branches/thasling/DistributedGA/DistributedGA.Hive/P2PMigrationAnalyzer.cs

    r13960 r13965  
    4141  [Item("P2PMigrationAnalyzer", "Migrates individuals using a P2P network.")]
    4242  [StorableClass]
    43   public class P2PMigrationAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator {
     43  public class P2PMigrationAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator, IExecutable {
    4444    // state: messagehandler
    4545    private IMessageHandler h;
     
    118118      validValues.Add(new EnumValue<MigrationStrategy>(MigrationStrategy.TakeRandomReplaceRandom));
    119119
    120       Parameters.Add(new ConstrainedValueParameter<EnumValue<MigrationStrategy>>("MigrationStrategy", validValues));
     120      Parameters.Add(new ConstrainedValueParameter<EnumValue<MigrationStrategy>>("MigrationStrategy", validValues, (new EnumValue<MigrationStrategy>(MigrationStrategy.TakeBestReplaceBad))));
    121121    }
    122122
     
    172172            using (var stream = new MemoryStream()) {
    173173              var emigrantScope = emigrantsList[ei];
     174              emigrantScope.ClearParentScopes();
    174175              var msgScope = new Scope();
    175176              var cloner = new Cloner();
     
    177178                msgScope.Variables.Add((IVariable)variable.Clone(cloner));
    178179              }
    179               // emigrantScope.ClearParentScopes();
     180              msgScope.ClearParentScopes();
     181              //TODO: CLEAR EMMIGRANT SCOPES
    180182              HeuristicLab.Persistence.Default.Xml.XmlGenerator.Serialize(msgScope, stream);
    181183              message[ei] = stream.GetBuffer();
     
    228230
    229231    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
    230274  }
    231275}
Note: See TracChangeset for help on using the changeset viewer.