我正在尝试使用GeneticSharp解决一个作业分配问题。它正在为卡车分配闸门,并不是所有的闸门都适合卡车。每条染色体都需要具有与基因指数相对应的特定双值数组中的基因值(每个基因指数等于卡车编号)。因此,我尝试从该数组中随机获取一个值并分配给FloatingPointChromosome类中的基因,但这给出了一个错误:“object reference not set to a object instance . allowedStands I”。
你能告诉我如何解决这个问题吗?
public FloatingPointChromosome(double[] minValue, double[] maxValue, int[] totalBits, int[] fractionDigits, double[] geneValues, double[][] allowedStands)
: base(totalBits.Sum())
{
m_minValue = minValue;
m_maxValue = maxValue;
m_totalBits = totalBits;
m_fractionDigits = fractionDigits;
// If values are not supplied, create random values
if (geneValues == null)
{
geneValues = new double[minValue.Length];
//var rnd = RandomizationProvider.Current;
var rnd = new Random();
for (int i = 0; i < geneValues.Length; i++)
{
int a = rnd.Next(allowedStands[i].Length);
geneValues[i] = allowedStands[i][a];
//I make here that it randomly selects from allowed gates array
}
}
m_originalValueStringRepresentation = String.Join(
"",
BinaryStringRepresentation.ToRepresentation(
geneValues,
totalBits,
fractionDigits));
CreateGenes();
}发布于 2018-10-05 08:58:15
我想在卡车和门分配的情况下更好,你可以创建自己的染色体,看看TspChromosome就可以得到一个想法。
public TspChromosome(int numberOfCities) : base(numberOfCities)
{
m_numberOfCities = numberOfCities;
var citiesIndexes = RandomizationProvider.Current.GetUniqueInts(numberOfCities, 0, numberOfCities);
for (int i = 0; i < numberOfCities; i++)
{
ReplaceGene(i, new Gene(citiesIndexes[i]));
}
}使用同样的方法,您的城市索引就是您的gates索引。
https://stackoverflow.com/questions/52059360
复制相似问题