Skip to content

Instantly share code, notes, and snippets.

@bdupreez
bdupreez / Chapter5.java
Created July 22, 2013 19:01
PCI Chapter 5 main methods
/**
* Hill Climbing
*
* @param domain list of tuples with min and max
* @return the bottom of the hill (local minimum)
*/
public int[] hillClimb(final List<Pair<Integer, Integer>> domain) {
//create random
int[] sol = new int[domain.size()];
Random random = new Random();
@bdupreez
bdupreez / gist:6056518
Created July 22, 2013 18:55
Corrected PCI chapter 5 code
def hillclimb(domain, costf):
# Create a random solution
sol = [random.randint(domain[i][0], domain[i][1])
for i in range(len(domain))]
# Main loop
while 1:
# Create list of neighboring solutions
neighbors = []
for j in range(len(domain)):