Example #1
0
        public NodeGene remove(int id)
        {
            ReceptorGene g1 = this.receptorGenes.FirstOrDefault(g => g.Id == id);

            if (g1 != null)
            {
                this.receptorGenes.Remove(g1);
                return(g1);
            }

            HandlerGene g2 = this.handlerGenes.FirstOrDefault(g => g.Id == id);

            if (g2 != null)
            {
                this.handlerGenes.Remove(g2);
                return(g2);
            }

            InferenceGene g3 = this.inferenceGenes.FirstOrDefault(g => g.Id == id);

            if (g3 != null)
            {
                this.inferenceGenes.Remove(g3);
                return(g3);
            }
            return(null);
        }
Example #2
0
        public static NWSEGenome Parse(String str)
        {
            if (str == null || str.Trim() == "")
            {
                return(null);
            }
            List <String> s1 = str.Split(new String[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList();

            if (s1 == null || s1.Count <= 0)
            {
                return(null);
            }

            NWSEGenome genome = new NWSEGenome();

            genome.id = int.Parse(s1[0]);
            s1.RemoveAt(0);

            if (int.TryParse(s1[0], out genome.generation))
            {
                s1.RemoveAt(0);
            }

            foreach (String s in s1)
            {
                if (s == null || s.Trim() == "")
                {
                    continue;
                }
                if (s.StartsWith("ReceptorGene"))
                {
                    genome.receptorGenes.Add(ReceptorGene.parse(genome, s));
                }
                else if (s.StartsWith("HandlerGene"))
                {
                    genome.handlerGenes.Add(HandlerGene.parse(genome, s));
                }
                else if (s.StartsWith("InferenceGene"))
                {
                    genome.inferenceGenes.Add(InferenceGene.parse(genome, s));
                }
                else if (s.StartsWith("handlerSelectionProb"))
                {
                    int s2 = s.IndexOf("handlerSelectionProb");
                    s2 = s.IndexOf("=", s2 + 1);
                    String s3 = s.Substring(s2 + 1).Trim();
                    genome.handlerSelectionProb.Clear();
                    genome.handlerSelectionProb.AddRange(Utility.parse(s3));
                }
                else if (s.StartsWith("vaild"))
                {
                    String s2 = s.Substring(s.IndexOf("="));
                    genome.validInferenceGenes.Add(NodeGene.parseGene(genome, s2));
                }
            }

            genome.computeNodeDepth();
            return(genome);
        }
Example #3
0
        private List <ReceptorGene> createReceptors(NWSEGenome genome, Session session)
        {
            List <Configuration.Sensor> sensors = Session.GetConfiguration().agent.receptors.GetAllSensor();

            for (int i = 0; i < sensors.Count; i++)
            {
                ReceptorGene receptorGene = new ReceptorGene(genome);
                receptorGene.Cataory     = sensors[i].cataory;
                receptorGene.Generation  = session.Generation;
                receptorGene.Group       = sensors[i].group;
                receptorGene.Name        = sensors[i].name;
                receptorGene.Description = sensors[i].desc;
                receptorGene.Id          = session.GetIdGenerator().getGeneId(receptorGene);
                genome.receptorGenes.Add(receptorGene);
            }
            return(genome.receptorGenes);
        }