i.lover3000
پنج شنبه 18 خرداد 1391, 15:00 عصر
سلام به همگی
من این کد را با استفاده از کانورتر از سی شارپ به وی بی دات نت تبدیل کردم.
ولی به این خط
Implements IFitnessFunction
گیر میده
متن خطا :
Class 'QueenFitnessFunction' must implement 'Function Evaluate(chromosome As IChromosome) As Double' for interface 'AForge.Genetic.IFitnessFunction'
using System;
using AForge.Genetic;
namespace AForgeGeneticNQueen
{
/// <summary>
/// Contains Evaluate function that evaluates fitness of the chromosome
/// </summary>
public class QueenFitnessFunction : IFitnessFunction
{
public double Evaluate(IChromosome chromosome)
{
double collisions = 0;
PermutationChromosome pch = chromosome as PermutationChromosome;
for (int i = 0; i < pch.Length - 1; i++)
for (int j = i + 1; j < pch.Length; j++)
if (Math.Abs(j - i) == Math.Abs(pch.Value[j] - pch.Value[i]))
collisions++;
return pch.Length - collisions;
}
}
}
Imports AForge.Genetic
Imports System
''' <summary>
''' Contains Evaluate function that evaluates fitness of the chromosome
''' </summary>
Public Class QueenFitnessFunction
Implements IFitnessFunction
Public Function Evaluate(ByVal chromosome As IChromosome) As Double
Dim collisions As Double = 0
Dim pch As PermutationChromosome = TryCast(chromosome, PermutationChromosome)
For i As Integer = 0 To pch.Length - 2
For j As Integer = i + 1 To pch.Length - 1
If Math.Abs(j - i) = Math.Abs(pch.Value(j) - pch.Value(i)) Then
collisions += 1
End If
Next
Next
Return pch.Length - collisions
End Function
End Class
من این کد را با استفاده از کانورتر از سی شارپ به وی بی دات نت تبدیل کردم.
ولی به این خط
Implements IFitnessFunction
گیر میده
متن خطا :
Class 'QueenFitnessFunction' must implement 'Function Evaluate(chromosome As IChromosome) As Double' for interface 'AForge.Genetic.IFitnessFunction'
using System;
using AForge.Genetic;
namespace AForgeGeneticNQueen
{
/// <summary>
/// Contains Evaluate function that evaluates fitness of the chromosome
/// </summary>
public class QueenFitnessFunction : IFitnessFunction
{
public double Evaluate(IChromosome chromosome)
{
double collisions = 0;
PermutationChromosome pch = chromosome as PermutationChromosome;
for (int i = 0; i < pch.Length - 1; i++)
for (int j = i + 1; j < pch.Length; j++)
if (Math.Abs(j - i) == Math.Abs(pch.Value[j] - pch.Value[i]))
collisions++;
return pch.Length - collisions;
}
}
}
Imports AForge.Genetic
Imports System
''' <summary>
''' Contains Evaluate function that evaluates fitness of the chromosome
''' </summary>
Public Class QueenFitnessFunction
Implements IFitnessFunction
Public Function Evaluate(ByVal chromosome As IChromosome) As Double
Dim collisions As Double = 0
Dim pch As PermutationChromosome = TryCast(chromosome, PermutationChromosome)
For i As Integer = 0 To pch.Length - 2
For j As Integer = i + 1 To pch.Length - 1
If Math.Abs(j - i) = Math.Abs(pch.Value(j) - pch.Value(i)) Then
collisions += 1
End If
Next
Next
Return pch.Length - collisions
End Function
End Class