哪位能帮我把这个c#程序转化为c++的?

来源:百度知道 编辑:UC知道 时间:2024/06/01 07:32:54
using System;

namespace SimulateAnnealing

{

class Class1

{

// 要求最优值的目标函数

static double ObjectFunction( double x, double y )

{

double z = 0.0;

z = 5.0 * Math.Sin(x*y) + x*x + y*y;

return z;

}

[STAThread]

static void Main(string[] args)

{

// 搜索的最大区间

const double XMAX = 4;

const double YMAX = 4;

// 冷却表参数

int MarkovLength = 10000; // 马可夫链长度

double DecayScale = 0.95; // 衰减参数

double StepFactor = 0.02; // 步长因子

double Temperature = 100; // 初始温度

double Tolerance = 1e-8; // 容差

double PreX,NextX; // prior and next value of x

double PreY,NextY; // prior and next value of y

double PreBestX, PreBestY; // 上一个最优解

double BestX,BestY; // 最终解

double AcceptPoints = 0.0; // Metropolis过程中总接受点
<

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
static double ObjectFunction( double x, double y )
{
double z = 0.0;
z = 5.0 * sin(x*y) + x*x + y*y;
return z;
}

void main()
{
// 搜索的最大区间
const double XMAX = 4;
const double YMAX = 4;
// 冷却表参数
int MarkovLength = 10000; // 马可夫链长度
double DecayScale = 0.95; // 衰减参数
double StepFactor = 0.02; // 步长因子
double Temperature = 100; // 初始温度
double Tolerance = 1e-8; // 容差
double PreX,NextX; // prior and next value of x
double PreY,NextY; // prior and next value of y
double PreBestX, PreBestY; // 上一个最优解
double BestX,BestY; // 最终解
double AcceptPoints = 0.0; // Metropolis过程中总接受点
// 随机选点
PreX = -XMAX * rand()*1.0/RAND_MAX;
PreY = -YMAX * rand()*1.0/RAND_MAX;
PreBestX = BestX = PreX;
PreBestY = BestY = PreY;
// 每迭代一次退火一次(降温), 直到满足迭代条件为止
d