模拟退火模板

模拟退火模板

#include<bits/stdc++.h>
#define MAX_TIME 0.9//时间限制(s)
#define Fu(i,a,b) for(register int i=(a);i<=(b);i++)
using namespace std;
double Rand(){ return 1.0*rand()/RAND_MAX;}
int calc(int z,int s[605],int x){
    //计算差值
	if(ans<=) //更新按时
	return ;
}
void saa(){
	double t=100000;//初始温度
	while(t>0.0001){
		int delta=calc(); //now-->now'
		if(exp(/*根据题目看加不加负号*/delta/t)>Rand()) //更新
		t*=0.999;//冷却
	}
	Fu(i,1,1000) //再跑1000遍更新ans,ans-->ans'
	return;
}
int main(){
	srand(time(0));
	while((double)clock()/CLOCKS_PER_SEC<MAX_TIME) saa();//跑到时间限制
	return 0;
}
posted @ 2024-02-22 19:39  zhy_learn  阅读(10)  评论(0编辑  收藏  举报