Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if h(next_state) < h(current_state):
- current_state = next_state
- else:
- if e^h... > random_float(0, 1):
- current_state = next_state
- def h(state):
- conflicts = 0
- for u in range(n):
- for v in adj[u]:
- if state[u] == 1 and state[v] == 1:
- conflicts += 1
- if conflicts == 0:
- sum = 0 # how many of them are chosen in the set
- for i in range(n):
- if (state[i] == 1):
- sum += 1
- return -sum
- return conflicts
Advertisement
Add Comment
Please, Sign In to add comment