繁体   English   中英

错误CS0246:找不到类型或名称空间名称“ AForge”。 您是否缺少using指令或程序集引用?

[英]error CS0246: The type or namespace name `AForge' could not be found. Are you missing a using directive or an assembly reference?

我正在尝试使用Unity3D中的遗传算法制作n个皇后,但是每次都会出现此错误...

码:

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;
        }
    }
}
}

我已经重新创建了您遇到的问题。 您在项目的\\Assets文件夹中缺少AForge.dll文件。

您要查找的DLL应该位于AForge.NET Framework-xxx-(libs only)\\Release文件夹中,该文件夹可能是从AForge.NET网站下载的压缩文件。

如果仍然很难找到它,请考虑选择[ Download Libraries Only ]下载整个软件包:

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

我还修复了您在那里遇到的一些问题。 如果已经将int.Parse()声明为int,则无需使用int.Parse()转换int值。 只需对正在使用的函数进行Math.Max(x, y)等。 另外,您没有使用AForge.Math命名空间中的任何内容。 如果是故意的,请考虑using AForge.Math;删除using AForge.Math; 因为它没有被使用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM