Home > other >  The student party, want to ask for take a look at this genetic algorithm application
The student party, want to ask for take a look at this genetic algorithm application

Time:10-26

Can help you, as long as a result OK hot

CodePudding user response:

5, 5 from 18

CodePudding user response:

 
J=[(1, 5), (2, 8), (5, 1), (7, 6), (8, 3)]
# from the initial value
Result=1000
# coordinates, the initial value
X, Y=0, 0
For x in range (9) :
For y in range (9) :
Number=[]
# circulation judge distances
For I in j:
Num=pow ((pow ((x - I [0]), 2) + pow ((y - I [1]), 2)), 1/2)
Number. Append (num)
# computing the total distance is the minimum
If the sum (number) & lt; Result:
X=X
Y=Y
Result=sum (number)
Print (X, Y, result)

CodePudding user response:

The import math

,1,2,3,4,5,6,7,8 list_x=[0]
,1,2,3,4,5,6,7,8 list_y=[0]
List_guest=[[1, 5], [2], [5, 1], [7], [8]]
Max_len max_X, max_Y, len=0, 0, 0, 0
For X in list_x:
For Y in list_y:
For guest in list_guest:
Len=len + math. SQRT ((X - guest [0]) * * 2 + (Y - guest [1]) * * 2)
If max_len & lt; Len:
Max_len=len
Max_X=X
Max_Y=Y
Len=0

Print (max_len max_X, max_Y)
  • Related