基于遗传算法的机组组合问题的建模与求解 第6页
附录1 问题1的C++求解程序
#include <iostream>
#include <fstream>
using namespace std;
double cost1(double x);
double cost2(double x);
int get_total_price();
void fun(int i);
ofstream fout("11.doc");
const int hour = 5;
// 最大出力
int pmax[2] = {200, 100};
// 最大增出力
int pcmax[2] = {30, 40};
// 最大减出力
int pdmax[2] = {50, 60};
// 状态
int state[2][hour] = {{1}, {0}};
// 负荷
int demand[5] = {0, 100, 130, 170, 140};
// 启动费用
int start[2] = {350, 100};
// 机组各时段状态
int power[2][5] = {{100}, {0}};
// 系统备用要求
int b_power[hour] = {0, 20, 30, 50, 40};
// 最小费用
int minprice = 9999999;
int main()
{
fun(1);
return 0;
}
// 机组1成本
double cost1(double x)
{
if (x <= 100)
{
return 100 + 10*x;
}
else
{
return 14*x - 300;
}
}
// 机组2成本
double cost2(double x)
{
if (x <= 60)
{
return 12*x + 200;
}
else
{
return 15*x + 20;
}
}
// 总成本
int get_total_price()
{
int i = 0, j;
double price = 0;
for (j = 1; j < hour; j++)
{
price += state[i][j]*cost1(power[i][j])
+ state[i][j]*(1-state[i][j-1])*start[i];
}
i = 1;
for (j = 1; j < hour; j++)
{
price += state[i][j]*cost2(power[i][j])
+ state[i][j]*(1-state[i][j-1])*start[i];
}
minprice = (minprice > price ? price: minprice);
//cout << minprice << " ";
fout << minprice << " ";
return price;
}
void fun(int i)
{
for (int j = -50; j <= 30; j+= 1)
{
// 机组1
power[0][i] = power[0][i-1] + j;
// 机组1出力范围约束
if (power[0][i] < 0 || power[0][i] > 200)
{
continue;
}
// 机组1增出力和减出力约束
if ( ((power[0][i]-power[0][i-1]) > pcmax[0]) && (power[0][i] > power[0][i-1])
|| ((power[0][i-1]-power[0][i]) > pdmax[0]) && (power[0][i-1] > power[0][i]))
{
continue;
}
// 机组2
// 负荷平衡约束
www.751com.cn
// 机组1状态
if (power[0][i] > 0)
{
state[0][i] = 1;
}
else
{
state[0][i] = 0;
}
// 机组2状态
if (power[1][i] > 0)
{
state[1][i] = 1;
}
else
{
state[1][i] = 0;
}
// 系统备用约束
上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页