错误CS0246:类型或命名空间名称`AForge';找不到.是否缺少using指令或程序集引用

本文关键字:是否 找不到 using 引用 程序集 指令 类型 CS0246 命名空间 AForge 错误 | 更新日期: 2023-09-27 18:25:09

我正试图在Unity3D中用遗传算法制作一个n-Queens,但每次都会出现这个错误。。。

代码:

using UnityEngine;
using System;
using System.Collections;
using AForge.Genetic;
using AForge.Math;
namespace AlgoritmoGenetico
{
public class GA : MonoBehaviour {
    int populationSizeBox;
    int iterationsBox;
    int nRainhasBox;
    int crossoverRateBox;
    int motacaoRateBox;
    int paradaBox;
    //int selecao;
    private String log = "";
    private int nRainhas = 14;
    private int nPopulacao = 14;
    private int nGeracoes = 8000;
    private int nParada = 100;
    private double crossoverRate = 0.75;
    private double mutationRate = 0.01;

    // Use this for initialization
    void Start () {
        Iniciar ();
    }
    // Update is called once per frame
    void Update () {
    }
    public void Iniciar(){
        configuraAlgoritimo();
        int selecao = 0; // definimos para o metodo roleta
        ISelectionMethod metodoDeSelecao = (selecao == 0) ? (ISelectionMethod)new RouletteWheelSelection() :
            (selecao == 1) ? (ISelectionMethod)new EliteSelection() :
                (ISelectionMethod)new RankSelection();
        AvaliadorDeRainhas avaliador = new AvaliadorDeRainhas();
        Population populacao = new Population(nPopulacao, new ShortArrayChromosome(nRainhas, nRainhas - 1), avaliador, metodoDeSelecao);
        populacao.CrossoverRate = crossoverRate;
        populacao.MutationRate = mutationRate;

        int iteracao = 0;
        int pararEm = nParada;
        while (iteracao < nGeracoes)
        {
            populacao.RunEpoch();
            if (nParada > 0 && iteracao == pararEm)
            {
                atualizaDadosPara(iteracao, populacao);
                pararEm += nParada;
            }
            if (populacao.BestChromosome.Fitness == nRainhas)
                break;
            iteracao++;
        }
        atualizaDadosPara(iteracao,populacao);
    }
    private void atualizaDadosPara(int iteracao,Population populacao)
    {
        log = "Geração: " + iteracao +
            "'n Método de Seleção : " + populacao.SelectionMethod +
                "'n Avaliação Média: " + populacao.FitnessAvg +
                "'n Melhor Avaliação : " + populacao.FitnessMax +
                "'n Melhor indivíduo: " + populacao.BestChromosome.ToString();
        print (log);
    }
    private void configuraAlgoritimo(){
        try
        {
            nPopulacao = Math.Max(10, Math.Min(100, int.Parse(populationSizeBox)));
        }
        catch
        {
            nPopulacao = 8;
        }
        try
        {
            nGeracoes = Math.Max(0, int.Parse(iterationsBox));
        }
        catch
        {
            nGeracoes = 100;
        }
        try
        {
            nRainhas = Math.Max(4, int.Parse(nRainhasBox));
        }
        catch
        {
            nRainhas = 8;
        }
        try
        {
            crossoverRate = Math.Max(0.0, int.Parse(crossoverRateBox));
        }
        catch
        {
            crossoverRate = 0.75;
        }
        try
        {
            mutationRate = Math.Max(0.0, int.Parse(motacaoRateBox));
        }
        catch
        {
            mutationRate = 0.01;
        }
        try
        {
            nParada = Math.Max(0, int.Parse(paradaBox));
        }
        catch
        {
            nParada = 0;
        }
    }
}
}

错误CS0246:类型或命名空间名称`AForge';找不到.是否缺少using指令或程序集引用

我已经重新创建了您案例中出现的问题。项目的'Assets文件夹中缺少AForge.dll文件。

您正在寻找的DLL应该位于AForge.NET Framework-x.x.x-(libs only)'Release文件夹中,您可能已经从AForge.NET网站上下载了该文件夹。

如果你仍然很难找到它,可以考虑从选择[ Download Libraries Only ]:重新下载整个包

http://www.aforgenet.com/framework/downloads.html

我还解决了你在那里遇到的一些问题。如果int值已经声明为int,则不需要使用int.Parse()强制转换它。只需使用您正在使用的函数执行Math.Max(x, y)等即可。此外,您没有使用AForge.Math命名空间中的任何内容。如果这是有意的,请考虑删除未使用的using AForge.Math;

相关文章: