• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Individual类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Individual的典型用法代码示例。如果您正苦于以下问题:C# Individual类的具体用法?C# Individual怎么用?C# Individual使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Individual类属于命名空间,在下文中一共展示了Individual类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CrossoverFunc

        public Tuple<IIndividual<Wrapper<LearningObject>>, IIndividual<Wrapper<LearningObject>>> CrossoverFunc(IIndividual<Wrapper<LearningObject>> individualA, IIndividual<Wrapper<LearningObject>> individualB)
        {
            int minlen = Math.Min(individualA.Chromosome.Genes.Count, individualB.Chromosome.Genes.Count);
            Tuple<IIndividual<Wrapper<LearningObject>>, IIndividual<Wrapper<LearningObject>>> tmpTuple;
            if (minlen > 2)
            {
                var fistChild = CrossIndividuals(individualA, individualB);
                var secondChild = CrossIndividuals(individualB, individualA);
                tmpTuple = new Tuple<IIndividual<Wrapper<LearningObject>>, IIndividual<Wrapper<LearningObject>>>(fistChild, secondChild);
            }
            else
            {
                IIndividual<Wrapper<LearningObject>> ind1 = new Individual<Wrapper<LearningObject>>();
                foreach (var gene in individualA.Chromosome.Genes)
                {
                    ind1.Chromosome.Genes.Add(new Wrapper<LearningObject>(gene.Used, gene.Value));
                }

                IIndividual<Wrapper<LearningObject>> ind2 = new Individual<Wrapper<LearningObject>>();
                foreach (var gene in individualB.Chromosome.Genes)
                {
                    ind2.Chromosome.Genes.Add(new Wrapper<LearningObject>(gene.Used, gene.Value));
                }

                tmpTuple = new Tuple<IIndividual<Wrapper<LearningObject>>, IIndividual<Wrapper<LearningObject>>>(ind1, ind2);
            }

            return tmpTuple;
        }
开发者ID:wadim1611,项目名称:222CourseBuildingsSystemMVCandWCF,代码行数:29,代码来源:CourseSecGAOperators.cs


示例2: Start

    // Use this for initialization
    void Start()
    {
        Debug.Log("Population size: " + populationSize);
        int width = (int)Mathf.Round(Mathf.Sqrt(populationSize));
        int height = (int)Mathf.Round(Mathf.Sqrt(populationSize));

        testing = new ComputeBuffer(10, Marshal.SizeOf(typeof(Individual)));

        Debug.Log("Seed " + DateTime.Now.Millisecond);

        // Fill with random genome, and run first fitness test.
        int kernel = shader.FindKernel("InitializePopulation");
        DebugAux.Assert(kernel >= 0, "Couldn't find kernel: " + "InitializePopulation " + kernel);
        shader.SetBuffer(kernel, "Population", testing);
        shader.SetFloat("seed", DateTime.Now.Millisecond);
        shader.Dispatch(kernel, 32, 32, 1);

        Individual[] tes = new Individual[10];
        testing.GetData(tes);
        for (int i = 0; i < tes.Length; i++)
            Debug.Log(tes[i].genome + " " + tes[i].fitness);

        // Selection..
        /*kernel = shader.FindKernel("AllOnesFitness");
        DebugAux.Assert(kernel >= 0, "Couldn't find kernel: " + "AllOnesFitness " + kernel);
        shader.SetBuffer(kernel, "Population", testing);
        shader.Dispatch(kernel, 32, 32, 1);*/

        testing.Dispose();
    }
开发者ID:KalleSjostrom,项目名称:Genome,代码行数:31,代码来源:GeneticAlgorithmCS.cs


示例3: evaluate

        public override void evaluate(EvolutionState state,
			                      Individual ind,
			                      int subpopulation,
			                      int threadnum)
        {
            try
            {
                this.state = state;
                this.ind = ((GPIndividual)ind);
                this.subpopulation = subpopulation;
                this.threadnum = threadnum;

                model.problem = this;
                // Signal model to start simulation
                model._signal.Set();
                // Model plays out scene with individual and sets fitness
                _signal.WaitOne();

                Debug.Log("Fitness " + model.fitness + " Result " + model.result
                    + " = " + this.ind.trees [0].child.makeCTree(true, true, true));

                KozaFitness f = ((KozaFitness)ind.fitness);
                f.setStandardizedFitness(state, model.fitness);
                f.hits = 0;
                ind.evaluated = true;
            } catch (Exception e)
            {
                Debug.LogError(e.Message);
                throw new Exception("Error while evaluating: ", e);
            }
        }
开发者ID:xanax,项目名称:unity-ecj,代码行数:31,代码来源:UnityProblem.cs


示例4: Main

        public static void Main()
        {
            Bank bank = new Bank("SoftUni Bank");
            var e = bank.Accounts;
            foreach (var account in e)
            {
                Console.WriteLine(account);
            }

            try
            {
                Individual clientOne = new Individual("Pencho Pitankata", "Neyde", "1212121230");
                Company clientTwo = new Company("SoftUni", "Hadji Dimitar", "831251119", true);
                DepositAccount depositOne = new DepositAccount(clientOne, 5, 10000);
                DepositAccount depositTwo = new DepositAccount(clientOne, 2, 100, new DateTime(2000, 01, 01));
                DepositAccount depositThree = new DepositAccount(clientOne, 2, 10000, new DateTime(2008, 01, 01));
                LoanAccount loanOne = new LoanAccount(clientOne, 14, 10000, new DateTime(2003, 01, 01));
                LoanAccount loanTwo = new LoanAccount(clientTwo, 14, 10000, new DateTime(2003, 01, 01));
                MortgageAccount mortgageOne = new MortgageAccount(clientOne, 7, 100000, new DateTime(2013, 08, 01));
                MortgageAccount mortgageTwo = new MortgageAccount(clientTwo, 7, 100000, new DateTime(2014, 08, 01));
                Console.WriteLine("Deposit Account 1 Interest: {0:F2}", depositOne.Interest());
                Console.WriteLine("Deposit Account 2 Interest: {0:F2}", depositTwo.Interest());
                Console.WriteLine("Deposit Account 3 Interest: {0:F2}", depositThree.Interest());
                Console.WriteLine("Loan Account Individual Interest: {0:F2}", loanOne.Interest());
                Console.WriteLine("Loan Account Company Interest: {0:F2}", loanTwo.Interest());
                Console.WriteLine("Mortgage Account Interest: {0:F2}", mortgageOne.Interest());
                Console.WriteLine("Mortgage Account Interest: {0:F2}", mortgageTwo.Interest());
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
            }
        }
开发者ID:tormibg,项目名称:SoftUni-1,代码行数:33,代码来源:TestRun.cs


示例5: Add

        public ActionResult Add(FormCollection form)
        {
            var individualToAdd = new Individual();

            // Deserialize (Include white list!)
            TryUpdateModel(individualToAdd, new string[] { "Name", "DateOfBirth" }, form.ToValueProvider());

            // Validate
            if (String.IsNullOrEmpty(individualToAdd.Name))
                ModelState.AddModelError("Name", "Name is required!");
            if (String.IsNullOrEmpty(individualToAdd.DateOfBirth))
                ModelState.AddModelError("DateOfBirth", "DateOfBirth is required!");

            var error = individualToAdd.ValidateDateOfBirth();
            if (!String.IsNullOrEmpty(error))
                ModelState.AddModelError("DateOfBirth", error);

            // If valid, save Individual to Database
            if (ModelState.IsValid)
            {
                _db.AddToIndividuals(individualToAdd);
                _db.SaveChanges();
                return RedirectToAction("Add");
            }

            // Otherwise, reshow form
            return View(individualToAdd);
        }
开发者ID:ravibeta,项目名称:NameDOB,代码行数:28,代码来源:HomeController.cs


示例6: CreateChild

        public Individual CreateChild(Individual parentA, Individual parentB, string geneSet)
        {
            const int charsToShift = 1;
            if (parentA.Genes.Length < charsToShift + 1)
            {
                return parentA;
            }
            bool shiftingPairLeft = Random.Next(2) == 1;
            string childGenes;
            int segmentStart = Random.Next(parentA.Genes.Length - charsToShift - 1);
            int segmentLength = Random.Next(charsToShift + 1, parentA.Genes.Length + 1 - segmentStart);
            string childGenesBefore = parentA.Genes.Substring(0, segmentStart);

            if (shiftingPairLeft)
            {
                string shiftedSegment = parentA.Genes.Substring(segmentStart, segmentLength - charsToShift);
                string shiftedPair = parentA.Genes.Substring(segmentStart + segmentLength - charsToShift, charsToShift);
                string childGenesAfter = parentA.Genes.Substring(segmentStart + segmentLength);
                childGenes = childGenesBefore + shiftedPair + shiftedSegment + childGenesAfter;
            }
            else
            {
                string shiftedPair = parentA.Genes.Substring(segmentStart, charsToShift);
                string shiftedSegment = parentA.Genes.Substring(segmentStart + charsToShift, segmentLength - charsToShift);
                string childGenesAfter = parentA.Genes.Substring(segmentStart + segmentLength);
                childGenes = childGenesBefore + shiftedSegment + shiftedPair + childGenesAfter;
            }
            var child = new Individual
            {
                Genes = childGenes,
                Strategy = this,
                Parent = parentA
            };
            return child;
        }
开发者ID:handcraftsman,项目名称:GeneticAlgorithms.Part3,代码行数:35,代码来源:ShiftStrategy.cs


示例7: PrintGroup

 public static void PrintGroup(int group, Individual i, TimetableData ttData)
 {
     System.Diagnostics.Debug.WriteLine("");
     System.Diagnostics.Debug.WriteLine("Group " + group);
     for (int block = 0; block < i.Courses.GetLength(2); block++)
     {
         System.Diagnostics.Debug.Write("Block " + block + ": ");
         for (int day = 0; day < 5; day++)
         {
             int course = i.Groups[group, day, block];
             if (course == -1)
             {
                 for (int j = 0; j < 44; j++)
                 {
                     System.Diagnostics.Debug.Write("-");
                 }
             }
             else
             {
                 string output = ttData.Courses[course].Name + ", " + ttData.Rooms[i.Courses[course, day, block]].Id;
                 System.Diagnostics.Debug.Write(output.PadRight(44, ' '));
             }
             System.Diagnostics.Debug.Write("| ");
         }
         System.Diagnostics.Debug.WriteLine("");
     }
 }
开发者ID:FalscherSchotte,项目名称:Timetable,代码行数:27,代码来源:TimetableExportDebug.cs


示例8: Run

        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // ****** Program ******

            // Initialize WorkbookDesigner object
            WorkbookDesigner designer = new WorkbookDesigner();
            // Load the template file
            designer.Workbook = new Workbook(dataDir + "SM_NestedObjects.xlsx");
            // Instantiate the List based on the class
            System.Collections.Generic.ICollection<Individual> list = new System.Collections.Generic.List<Individual>();
            // Create an object for the Individual class
            Individual p1 = new Individual("Damian", 30);
            // Create the relevant Wife class for the Individual
            p1.Wife = new Wife("Dalya", 28);
            // Create another object for the Individual class
            Individual p2 = new Individual("Mack", 31);
            // Create the relevant Wife class for the Individual
            p2.Wife = new Wife("Maaria", 29);
            // Add the objects to the list
            list.Add(p1);
            list.Add(p2);
            // Specify the DataSource
            designer.SetDataSource("Individual", list);
            // Process the markers
            designer.Process(false);
            // Save the Excel file.
            designer.Workbook.Save(dataDir+ "output.xlsx");

        }
开发者ID:aspose-cells,项目名称:Aspose.Cells-for-.NET,代码行数:33,代码来源:UsingNestedObjects.cs


示例9: cmdCreatClientWithAssociation_Click

        private void cmdCreatClientWithAssociation_Click(object sender, EventArgs e)
        {
            // create client
            var i1 = new Individual()
            {
                LastName = "Smith"
            };
            _gateway.Save(i1);
            var client = _gateway.ConvertContactToClient(i1, "034757", CssContext.Instance.Host.EmployeeId);

            // create contact
            var i2 = new Individual()
            {
                LastName = "Jones"
            };
            _gateway.Save(i2);

            //create relationship
            var r = new Relationship() {
                Contact1 = i1,
                Contact2 = i2,
                RelationshipId = 1 // spouse - from relationship table
            };
            _gateway.Save(r);

            CssContext.Instance.Host.OpenContact(i1.ContactId);
        }
开发者ID:joncoello,项目名称:CSExample,代码行数:27,代码来源:frmDataAPI.cs


示例10: TestIndividualConstructors

        public void TestIndividualConstructors()
        {
            ListGenotype<FloatGene> genotype1 = new ListGenotype<FloatGene>(new[] {new FloatGene(1)});
            ListGenotype<FloatGene> genotype2 = new ListGenotype<FloatGene>(new[] {new FloatGene(2)});

            Individual<ListGenotype<FloatGene>, int> individual1 =
                new Individual<ListGenotype<FloatGene>, int>(genotype1);
            Individual<ListGenotype<FloatGene>, int> individual2 =
                new Individual<ListGenotype<FloatGene>, int>(genotype2, 30);

            Assert.AreEqual(1, individual1.Genotype.Count);
            Assert.AreEqual(1, individual2.Genotype.Count);

            Assert.False(individual1.HasFitnessAssigned);
            Assert.True(individual2.HasFitnessAssigned);

            int a;
            Assert.Throws<InvalidOperationException>(() => a = individual1.Fitness);
            Assert.AreEqual(30, individual2.Fitness);

            ListGenotype<FloatGene> genotype3 = individual1.Genotype;
            Assert.AreSame(individual1.Genotype, genotype3);

            IList<Individual<ListGenotype<FloatGene>, int>> individuals =
                Individual<ListGenotype<FloatGene>, int>.FromGenotypes(new[] {genotype1, genotype2, genotype3});

            Assert.AreSame(individuals[0].Genotype, genotype1);
            Assert.AreSame(individuals[1].Genotype, genotype2);
            Assert.AreSame(individuals[2].Genotype, genotype3);
        }
开发者ID:bgarate,项目名称:Evolution,代码行数:30,代码来源:IndividualTest.cs


示例11: Main

    static void Main()
    {
        Individual ivan = new Individual("Ivan");
        Company tech = new Company("Tech OOD");

        MortageAcount firstAcc = new MortageAcount(ivan, 1000, 3);

        MortageAcount mortAcc = new MortageAcount(tech, 20000, 10);

        Console.WriteLine(mortAcc.CalculateInterestAmount(10)); //10 months * 10% / 2 = 10months * 5% from 20 000 = 10 000

        Console.WriteLine(mortAcc.CalculateInterestAmount(24)); //12m * 5% from 20000 and 12m * 10 % from 20000 = 12*1000 + 12*2000 = 36 000

        Console.WriteLine(firstAcc.CalculateInterestAmount(7)); //only 1 month (first 6 are no rate) * 3% from 1000 = 30

        DepositAcount depAcc = new DepositAcount(ivan, 700, 20);

        Console.WriteLine(depAcc.CalculateInterestAmount(99999)); // 0 - amount is 700 which is positive and less than 1000

        LoanAcount loanIndivid = new LoanAcount(ivan, 10000, 10);
        LoanAcount loanCompany = new LoanAcount(tech, 100000, 15);

        Console.WriteLine(loanIndivid.CalculateInterestAmount(3)); // 0 - free 3 months
        Console.WriteLine(loanIndivid.CalculateInterestAmount(4)); // free 3 months --> 1 * 10% from 10000 = 1000

        Console.WriteLine(loanCompany.CalculateInterestAmount(2)); // 0 - free 3 months
        Console.WriteLine(loanCompany.CalculateInterestAmount(4)); // free 2 months --> 2 * 15% from 100000 = 30000
    }
开发者ID:purlantov,项目名称:TelerikAcademy-4,代码行数:28,代码来源:BankTesting.cs


示例12: Main

    private static void Main()
    {
        Customer customerOne = new Individual("Radka Piratka");
        Customer customerTwo = new Company("Miumiunali Brothers");

        Account[] accounts =
        {
            new Deposit(customerOne, 7000, 5.5m, 18),
            new Deposit(customerOne, 980, 5.9m, 12),
            new Loan(customerOne, 20000, 7.2m, 2),
            new Loan(customerOne, 2000, 8.5m, 9),
            new Mortgage(customerOne, 14000, 5.4m, 5),
            new Mortgage(customerOne, 5000, 4.8m, 10),
            new Deposit(customerTwo, 10000, 6.0m, 12),
            new Mortgage(customerTwo, 14000, 6.6m, 18),
            new Loan(customerTwo, 15000, 8.9m, 2),
            new Loan(customerTwo, 7000, 7.5m, 12),
        };

        foreach (Account account in accounts)
        {
            Console.WriteLine(account);
        }

        Deposit radkaDeposit = new Deposit(customerOne, 980, 5.9m, 12);
        Deposit miumiuDeposit = new Deposit(customerTwo, 10000, 6.0m, 12);

        Console.WriteLine();
        Console.WriteLine("Current balance: {0}", radkaDeposit.WithdrawMoney(150));
        Console.WriteLine("Current balance: {0}", radkaDeposit.DepositMoney(1500));
        Console.WriteLine("Current balance: {0}", miumiuDeposit.WithdrawMoney(5642));
        Console.WriteLine("Current balance: {0}", miumiuDeposit.DepositMoney(1247));
    }
开发者ID:RuParusheva,项目名称:TelerikAcademy,代码行数:33,代码来源:Test.cs


示例13: CreateChild

 public Individual CreateChild(Individual parentA, Individual parentB, string geneSet)
 {
     int reversePointA = Random.Next(parentA.Genes.Length);
     int reversePointB = Random.Next(parentA.Genes.Length);
     if (reversePointA == reversePointB)
     {
         reversePointB = Random.Next(parentA.Genes.Length);
         if (reversePointA == reversePointB)
         {
             return parentA;
         }
     }
     int min = Math.Min(reversePointA, reversePointB);
     int max = Math.Max(reversePointA, reversePointB);
     var childGenes = parentA.Genes.ToCharArray();
     for (int i = 0; i <= (max - min) / 2; i++)
     {
         int lowIndex = i + min;
         int highIndex = max - i;
         char temp = childGenes[lowIndex];
         childGenes[lowIndex] = childGenes[highIndex];
         childGenes[highIndex] = temp;
     }
     var child = new Individual
     {
         Genes = new String(childGenes),
         Strategy = this,
         Parent = parentA
     };
     return child;
 }
开发者ID:handcraftsman,项目名称:GeneticAlgorithms.Part3,代码行数:31,代码来源:ReverseStrategy.cs


示例14: CreateChild

 public Individual CreateChild(Individual parentA, Individual parentB, string geneSet)
 {
     return new Individual
     {
         Genes = GenerateSequence(geneSet),
         Strategy = this
     };
 }
开发者ID:handcraftsman,项目名称:GeneticAlgorithms.Part3,代码行数:8,代码来源:RandomStrategy.cs


示例15: GetAncestors

 private static IEnumerable<Individual> GetAncestors(Individual bestIndividual)
 {
     while (bestIndividual != null)
     {
         yield return bestIndividual;
         bestIndividual = bestIndividual.Parent;
     }
 }
开发者ID:handcraftsman,项目名称:GeneticAlgorithms.Part3,代码行数:8,代码来源:GeneticSolver.cs


示例16: calculateFitness

 public override double calculateFitness(Individual ind)
 {
     if (ind.gens.Count < 3)
     {
         throw new Exception("Genanzahl im Individuum  kleiner 3. (" + ind.gens.Count + ")");
     }
     return solveSystem(ind);
 }
开发者ID:Shorthe,项目名称:Genetischer_Algorithmus,代码行数:8,代码来源:Standard_SoE.cs


示例17: ICrossoverStrategy_PerformCrossover_ThrowOnCrossoverBetweenSameIndividual

 public void ICrossoverStrategy_PerformCrossover_ThrowOnCrossoverBetweenSameIndividual()
 {
     var parent1 = new Individual(ValidGraph, ValidProblem);
     Assert.Throws<AlgorithmException>(() =>
     {
         Strategy.PerformCrossover(parent1, parent1);
     });
 }
开发者ID:m-wilczynski,项目名称:Graphinder,代码行数:8,代码来源:ICrossoverStrategyTests.cs


示例18: ComputeSchedulingTime

 public int ComputeSchedulingTime(Individual ind)
 {
     int[] biases = new int[MachinesCount];
     for (int i = 0; i < JobsCount; i++)
     {
         biases[ind.Chromosome[i]] += jobs[i];
     }
     return biases.Max();
 }
开发者ID:Xevaquor,项目名称:PUT-Poznan-Informatyka,代码行数:9,代码来源:GeneticAlgorithm.cs


示例19: Subscribe

 public static Community Subscribe(this Community community, Individual individual)
 {
     community
         .Subscribe(() => individual)
         .Subscribe(() => individual.Companies)
         .Subscribe(() => individual.Games)
         ;
     return community;
 }
开发者ID:michaellperry,项目名称:MyImproving,代码行数:9,代码来源:IndividualSubscription.cs


示例20: ComputeFitness

 public double ComputeFitness(Individual ind)
 {
     int[] biases = new int[MachinesCount];
     for (int i = 0; i < JobsCount; i++)
     {
         biases[ind.Chromosome[i]] += jobs[i];
     }
     return jobsSum - biases.Max() + 1; //force positive value
 }
开发者ID:Xevaquor,项目名称:PUT-Poznan-Informatyka,代码行数:9,代码来源:GeneticAlgorithm.cs



注:本文中的Individual类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# InflateManagerMode类代码示例发布时间:2022-05-24
下一篇:
C# Indicator类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap