Simulated annealing: Difference between revisions
m
→{{header|Phix}}: pp_StrFmt tweaks, removed b_a_exp(), and exp(x,-inf) attempt
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: Fix link: Perl 6 --> Raku) |
m (→{{header|Phix}}: pp_StrFmt tweaks, removed b_a_exp(), and exp(x,-inf) attempt) |
||
Line 749:
=={{header|Phix}}==
{{trans|zkl}}
<lang Phix>function hypot(atom a,b) return sqrt(a*a+b*b) end function
Line 778 ⟶ 776:
function T(integer k, kmax, kT) return (1-k/kmax)*kT end function
-- deltaE = Es_new - Es_old > 0
-- probability to move if deltaE > 0, -->0 when T --> 0 (frozen state)
function P(atom deltaE, integer k, kmax, kT) return
-- deltaE from path ( .. a u b .. c v d ..) to (.. a v b ... c u d ..)
Line 812 ⟶ 808:
if mod(k,kmax/10)=0 then
printf(1,"k:%,10d T: %8.4f Es: %8.4f\n",{k,T(k,kmax,kT),Es(s)})
if k=kmax then exit end if -- avoid exp(x,-inf)
end if
integer u = rand(99), -- city index 1 99
Line 828 ⟶ 825:
printf(1,"E(s_final) %f\n",Emin)
printf(1,"Path:\n")
pp(s,{pp_IntFmt,"%2d",
end procedure
sa(1_000_000,1)</lang>
|