模拟退火算法的原理
模拟退火算法来源于固体退火原理,将固体加温至充分高,再让其徐徐冷却,加温时,固体内部粒子随温升变为无序状,内能增大,而徐徐冷却时粒子渐趋有序,在每个温度都达到平衡态,最后在常温时达到基态,内能减为最小。根据Metropolis准则,粒子在温度T时趋于平衡的概率为e-ΔE/(kT),其中E为温度T时的内能,ΔE为其改变量,k为Boltzmann常数。用固体退火模拟组合优化问题,将内能E模拟为目标函数值f,温度T演化成控制参数t,即得到解组合优化问题的模拟退火算法:由初始解i和控制参数初值t开始,对当前解重复“产生新解→计算目标函数差→接受或舍弃”的迭代,并逐步衰减t值,算法终止时的当前解即为所得近似最优解,这是基于蒙特卡罗迭代求解法的一种启发式随机搜索过程。退火过程由冷却进度表(Cooling Schedule)控制,包括控制参数的初值t及其衰减因子Δt、每个t值时的迭代次数L和停止条件S。
模拟退火算法的模型
1模拟退火算法可以分解为解空间、目标函数和初始解三部分。
2模拟退火的基本思想:
(1) 初始化:初始温度T(充分大),初始解状态S(是算法迭代的起点),每个T值的迭代次数L
(2) 对k=1,……,L做第(3)至第(6)步:
(3) 产生新解S′
(4) 计算增量Δt′=C(S′)-C(S),其中C(S)为评价函数
(5) 若Δt′<0则接受S′作为新的当前解,否则以概率exp(-Δt′/T)接受S′作为新的当前解.
(6) 如果满足终止条件则输出当前解作为最优解,结束程序。终止条件通常取为连续若干个新解都没有被接受时终止算法。
(7) T逐渐减少,且T->0,然后转第2步。

Run Away

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 334    Accepted Submission(s): 114

Problem Description
One of the traps we will encounter in the Pyramid is located in the Large Room. A lot of small holes are drilled into the floor. They look completely harmless at the first sight. But when activated, they start to throw out very hot java, uh ... pardon, lava. Unfortunately, all known paths to the Center Room (where the Sarcophagus is) contain a trigger that activates the trap. The ACM were not able to avoid that. But they have carefully monitored the positions of all the holes. So it is important to find the place in the Large Room that has the maximal distance from all the holes. This place is the safest in the entire room and the archaeologist has to hide there.

Input
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing three integers X, Y, M separated by space. The numbers satisfy conditions: 1 <= X,Y <=10000, 1 <= M <= 1000. The numbers X and Yindicate the dimensions of the Large Room which has a rectangular shape. The number M stands for the number of holes. Then exactly M lines follow, each containing two integer numbers Ui and Vi (0 <= Ui <= X, 0 <= Vi <= Y) indicating the coordinates of one hole. There may be several holes at the same position.

Output
Print exactly one line for each test case. The line should contain the sentence "The safest point is (P, Q)." where P and Qare the coordinates of the point in the room that has the maximum distance from the nearest hole, rounded to the nearest number with exactly one digit after the decimal point (0.05 rounds up to 0.1).

Sample Input
3
1000 50 1
10 10
100 100 4
10 10
10 90
90 10
90 90
3000 3000 4
1200 85
63 2500
2700 2650
2990 100

Sample Output
The safest point is (1000.0, 50.0).
The safest point is (50.0, 50.0).
The safest point is (1433.0, 1669.8).

Source
Central Europe 1999

Recommend
Eddy

#include<stdio.h>
#include<string.h>
#include<time.h>
#include<math.h>
#include<iostream>
using namespace std;
struct solve
{
double x,y,val;
};
solve tr[51];
double recx[1025],recy[1025];
double X,Y;
int M;
double Evaluate(solve tt)
{
double Min=1e8;
int i;
for (i=1;i<=M;i++)
if ((tt.x-recx[i])*(tt.x-recx[i])+(tt.y-recy[i])*(tt.y-recy[i])<Min)
Min=(tt.x-recx[i])*(tt.x-recx[i])+(tt.y-recy[i])*(tt.y-recy[i]);
return Min;
}
void Simulated_Annealing()
{
double Temper=X+Y,eps=1e-3,dx,dy;
int i,j;
solve tmp;
for (i=1;i<=50;i++)
{
tr[i].x=((rand()%1000+1)*1.0/1000.00)*X;
tr[i].y=((rand()%1000+1)*1.0/1000.00)*Y;
tr[i].val=Evaluate(tr[i]);
}
while (Temper>eps)
{
for (i=1;i<=50;i++)
{
for (j=1;j<=50;j++)
{
dx=(double)(rand()%1000+1)*1.0/1000.00*Temper;
dy=sqrt(Temper*Temper-dx*dx);
if (rand()&1) dx*=-1;
if (rand()&1) dy*=-1;
tmp.x=tr[i].x+dx;
tmp.y=tr[i].y+dy;
if (tmp.x>=0 && tmp.x<=X && tmp.y>=0 && tmp.y<=Y)
{
double value=Evaluate(tmp);
if (value>tr[i].val)
{
tr[i]=tmp;
tr[i].val=value;
}
}
}
}
Temper*=0.6;
}
int url=1;
for (i=2;i<=50;i++)
if (tr[i].val>tr[url].val)
url=i;
printf("The safest point is (%.1lf, %.1lf).\n",tr[url].x,tr[url].y);
}
int main()
{
srand(unsigned(time(0)));
int T,i;
scanf("%d",&T);
while (T--)
{
scanf("%lf%lf%d",&X,&Y,&M);
for (i=1;i<=M;i++)
scanf("%lf%lf",&recx[i],&recy[i]);
Simulated_Annealing();
}
return 0;
}

模拟退火算法-[HDU1109]的更多相关文章

  1. 初探 模拟退火算法 POJ2420 HDU1109

    模拟退火算法来源于固体退火原理,更多的化学物理公式等等这里不再废话,我们直接这么来看 模拟退火算法简而言之就是一种暴力搜索算法,用来在一定概率下查找全局最优解 找的过程和固体退火原理有所联系,一般来讲 ...

  2. [HDU1109]模拟退火算法

    模拟退火的基本思想: (1) 初始化:初始温度T(充分大),初始解状态S(是算法迭代的起点),每个T值的迭代次数L (2) 对k=1,……,L做第(3)至第6步: (3) 产生新解$S\prime $ ...

  3. 【高级算法】模拟退火算法解决3SAT问题(C++实现)

    转载请注明出处:http://blog.csdn.net/zhoubin1992/article/details/46453761 ---------------------------------- ...

  4. 模拟退火算法(SA)求解TSP 问题(C语言实现)

    这篇文章是之前写的智能算法(遗传算法(GA).粒子群算法(PSO))的补充.其实代码我老早之前就写完了,今天恰好重新翻到了,就拿出来给大家分享一下,也当是回顾与总结了. 首先介绍一下模拟退火算法(SA ...

  5. 原创:工作指派问题解决方案---模拟退火算法C实现

    本文忽略了对于模拟退火的算法的理论讲解,读者可参考相关的博文或者其他相关资料,本文着重于算法的实现: /************************************************ ...

  6. BZOJ 3680: 吊打XXX【模拟退火算法裸题学习,爬山算法学习】

    3680: 吊打XXX Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 3192  Solved: 1198[Sub ...

  7. OI骗分神器——模拟退火算法

    前言&&为什么要学模拟退火 最近一下子学了一大堆省选算法,所以搞一个愉快一点的东西来让娱乐一下 其实是为了骗到更多的分,然后证明自己的RP. 说实话模拟退火是一个集物理与IT多方面知识 ...

  8. 模拟退火算法 R语言

    0 引言 模拟退火算法是用来解决TSP问题被提出的,用于组合优化. 1 原理 一种通用的概率算法,用来在一个打的搜索空间内寻找命题的最优解.它的原理就是通过迭代更新当前值来得到最优解.模拟退火通常使用 ...

  9. 模拟退火算法(西安网选赛hdu5017)

    Ellipsoid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

随机推荐

  1. vimcommandfilepatchcmdfold VIM技巧之分隔窗口 一级精华

    VIM技巧之分隔窗口 分类: 技术2010-07-08 09:57 754人阅读 评论(1) 收藏 举报   同时显示两个不同的文件, 或者同时查看同一个文件的两个不同位置, 或者是同步显示两个文件的 ...

  2. [BZOJ3872][Poi2014]Ant colony

    [BZOJ3872][Poi2014]Ant colony 试题描述 There is an entrance to the ant hill in every chamber with only o ...

  3. Linux统计文件个数

    查看某个文件夹下的文件个数用ls列目录,用grep过虑,再用wc统计即可 用ls -l列出后, 每一行对应一个文件或目录, 如果第一个字母为’-'则为普通文件, 若为’d'则为子目录 + +grep过 ...

  4. FireFox下上传控件的显示问题

    Chrome正常 FireFox显示不正常 上传控件一直有个问题,就是样式问题,解决方法就是用一个大的背景层挡住,然后点大的背景层去触发上传控件的Click事件. Html: <span id= ...

  5. MySQL数据库备份和还原的常用命令

    其实很多情况下mysql备份就是采用了这些命令,例如: mysql导入和导出数据 linux自动定时备份web程序和mysql数据库 备份MySQL数据库的命令 mysqldump -hhostnam ...

  6. ios如何生成crash报告

    #include <signal.h> #include <execinfo.h> void OnProcessExceptionHandler(int sigl) { do ...

  7. MYSQL 删除字段值为NULL的语法

    2014年9月1日 15:11:05 delete form your_table where your_field is null and your_field1 = '123' ...

  8. Thread源码分析

    本文为转载,请珍惜别人的劳动成果,注明转载地址:http://www.cnblogs.com/gw811/archive/2012/10/15/2724602.html 1.Runnable接口源码: ...

  9. Action返回类型

    1.返回ascx页面return PartialView(); 2.Content(),返回文本ContentResultreturn Content("这是一段文本"); 3.J ...

  10. fork

    #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <fcntl.h> ...