资源简介
多目标和声算法的源代码,是和声原始算法的升级版,主要用于求最优解
代码片段和文件信息
/*
IF YOU USE THIS CODE YOU CAN CITE THE FOLLOWING WORK:
[1] M. Fesanghary S. Asadi Z.W. Geem Design of Low-Emission and Energy-Efficient Residential Buildings Using a Multi-objective Optimization Algorithm Building and Environment 49 (2012) 245-250
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace MultiobjectiveHS
{
public class CostOptimizer : MOHS.IFunction
{
#region Fields
MOHS hs;
int nVar;
double[] xlb;
double[] xub;
int Iteration = 0;
public string address = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);
StreamWriter sw1;
double[] bestSolution;
string str1 = DateTime.Now.ToLongDateString();
string str2 = (DateTime.Now.Hour).ToString();
string str3 = (DateTime.Now.Minute).ToString();
string str4 = (DateTime.Now.Second).ToString();
string name2 name1;
#endregion
public void Solve()
{
name1 = address + “\\Report.txt“;
nVar = 2; // number of variables
xlb = new double[nVar];
xub = new double[nVar];
RunHS();
}
public double[] F(double[] x)
{
double[] f = new double[hs.nobjectives];
Iteration++;
try
{
f[0] = x[0] + Math.Exp(x[1]); // objective 1 = x0 + exp(x1)
f[1] = -2 * x[0] + Math.Exp(-x[1]); // objective 2 = -2x0 + exp(-x1)
}
catch (Exception e) // in case of error...!
{
f[0] = f[1] = double.MaxValue;
Console.WriteLine(e.Message);
}
#region Report
try
{
if (Iteration == 1) { File.Delete(name1); }
sw1 = File.AppendText(name1);
sw1.Write(Iteration.ToString() + “\t“);
sw1.Write(f[0].ToString(“e“) + “\t“ + f[1].ToString(“e“) + “\t“);
for (int i = 0; i < bestSolution.Length - 2; i++)
sw1.Write(x[i].ToString() + “\t“);
sw1.WriteLine();
sw1.Close();
if (Iteration % 10 == 0)
Console.WriteLine(“# “ + Iteration.ToString() + “ f0 = “ + (f[0]).ToString(“e“) + “ f1 = “ + (f[1]).ToString(“e“));
if (Iteration % 50 == 0)
{
hs.choosePareto();
Utility.WriteMatrix(hs.ParetoSet “Pareto Front“ “e3“);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
#endregion
return f;
}
public void R
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 890 2011-12-07 18:54 Multiob
文件 18432 2011-12-07 18:57 Multiob
目录 0 2011-12-07 18:58 Multiob
文件 4247 2011-12-07 18:56 Multiob
文件 14782 2011-12-07 18:56 Multiob
文件 2570 2011-12-07 18:56 Multiob
目录 0 2011-12-07 18:58 Multiob
文件 14782 2011-12-07 18:48 Multiob
文件 400 2011-12-07 18:56 Multiob
目录 0 2011-12-07 18:58 Multiob
文件 1450 2011-12-07 18:54 Multiob
文件 793 2011-12-07 18:32 Multiob
评论
共有 条评论