This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)): |