我是一名电气工程专业的学生,正在为我的最后一年项目制定住宅负荷调度问题。我对遗传算法和Java编程知之甚少,这超出了我的学习范围。如果有人能帮助我,我真的很感激。我为我提出的任何无知问题道歉。
我一直在阅读书籍和研究论文以了解GA。我的五年计划的目标是安排家用电器仅在电费最低的时候开启(假设价格每半小时变化一次)。
我决定使用遗传算法作为人工智能技术来解决问题,因为它可以有效地解决大量变量的问题。
假设一个住宅区由100个家庭单元组成,每个单元拥有3个可控负载(可以转移到其他操作时间而不影响用户舒适度的负载) - 洗衣机,干衣机和洗碗机。基本上,目标函数是最小化沿着时隙的(器具功耗,电价和它的开/关状态)的总和的乘积。目标是在48个时隙(时隙= 1/2小时)内找到这些设备的最佳解决方案(最低成本)。由于每个器具具有典型的开启时间(例如,洗衣机9-11pm,干燥器11pm-1am,和洗碗机7-10pm)。电价每半小时变化一次,并在时段内保持不变,最低电价通常在上午12点到早上8点之间。
我正在尝试将染色体实例化为包含m x n矩阵,其中m是设备数量(在本例中为3),n是时隙数量(48)。
示例:
其中0和1分别代表关闭和开启 染色体1: 洗衣机衣物烘干机洗碗机 [[0 0 0 ... 1 1 0 0 0] [0 0 0 ... 1 1 0] [0 0 0 ... 1 1 1 1 0 ... 00]] 格式为3 x 48矩阵
**UPDATES**
我对编码部分有一些疑问,如果你们能帮助我,我将不胜感激。
问题1:我正在尝试生成48个二进制0和1的数组,并且适合它来评估适应度。有人可以帮我识别他的错误吗?
package HEMS;
public class Individual {
/**
* In this case, the chromosome is an array of integers rather than a string.
*/
private int[] chromosome;
private double fitness = -1;
public static final int CHROMOSOME_LENGTH = 48;
/**
* Initializes individual with specific chromosome
*
* The chromosome to give individual
*/
public Individual(int[] chromosome) {
// Create individual chromosome
this.chromosome = chromosome;
}
/**
* Initializes random individual
*
* The length of the individuals chromosome
*/
public Individual(int chromosomeLength) {
// Create random individual
this.chromosome = new int[chromosomeLength];
/**
* This constructor assumes that the chromosome is made entirely of 0s and
* 1s, which may not always be the case, so make sure to modify as
* necessary. This constructor also assumes that a "random" chromosome means
* simply picking random zeroes and ones, which also may not be the case
*
*/
for (int gene = 0; gene < chromosomeLength; gene++) {
if (0.5 < Math.random()) {
this.setGene(gene, 1);
} else {
this.setGene(gene, 0);
}
}
}
/**
* Gets individual's chromosome
*
* @return The individual's chromosome
*/
public int[] getChromosome() {
return this.chromosome;
}
/**
* Gets individual's chromosome length
*
* @return The individual's chromosome length
*/
public int getChromosomeLength() {
return this.chromosome.length;
}
/**
* Set gene at offset
*
*/
public void setGene(int offset, int gene) {
this.chromosome[offset] = gene;
}
/**
* Get gene at offset
*
* @return gene
*/
public int getGene(int offset) {
return this.chromosome[offset];
}
/**
* Store individual's fitness
*
* The individuals fitness
*/
public void setFitness(double fitness) {
this.fitness = fitness;
}
/**
* Gets individual's fitness
*
* @return The individual's fitness
*/
public double getFitness() {
return this.fitness;
}
public String toString() {
String output = "";
for (int gene = 0; gene < this.chromosome.length; gene++) {
output += this.chromosome[gene] + ",";
}
return output;
}
}