PDA

View Full Version : مشکل این کد وقتی از #C به VB تبدیل میکنم



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

hhsaffar
پنج شنبه 18 خرداد 1391, 16:52 عصر
این کد رو امتحان کنید ببینید خطا از بین میره یا نه.
نحوه Implement کردن اینترفیس در VB.NET رو اینجا (http://www.itcsolutions.eu/2010/03/23/how-to-implement-interfaces-in-vb-net/) و اینجا (http://msdn.microsoft.com/en-us/library/f6x8ydw5(v=vs.71).aspx) بخونید.

Public Class QueenFitnessFunction
Implements IFitnessFunction
Public Function Evaluate(chromosome As IChromosome) As Double Implements IFitnessFunction.Evaluate
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

i.lover3000
پنج شنبه 18 خرداد 1391, 17:40 عصر
ممنون اون خطا رفع شد.