mitkonikov

Untitled

May 16th, 2023
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1.  
  2.  
  3.  
  4. if h(next_state) < h(current_state):
  5.     current_state = next_state
  6. else:
  7.    if e^h... > random_float(0, 1):
  8.         current_state = next_state
  9.  
  10.  
  11. def h(state):
  12.    conflicts = 0
  13.    for u in range(n):
  14.       for v in adj[u]:
  15.          if state[u] == 1 and state[v] == 1:
  16.              conflicts += 1
  17.    
  18.    if conflicts == 0:
  19.       sum = 0 # how many of them are chosen in the set
  20.       for i in range(n):
  21.           if (state[i] == 1):
  22.               sum += 1
  23.       return -sum
  24.    
  25.    return conflicts
Advertisement
Add Comment
Please, Sign In to add comment