Skip to content

Commit

Permalink
Minor changes to NPP example and logging format
Browse files Browse the repository at this point in the history
  • Loading branch information
rrei committed Mar 12, 2017
1 parent 2033e62 commit 83c2609
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/examples/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def karmarkar_karp(labels):
class NppTreeNode(mcts.TreeNode):

EXPANSION_LIMIT = float("inf") # 2 would also suffice
EXPLORATION_COEFF = 0.05
EXPLORATION_COEFF = 0.1


class NppState(mcts.State):
Expand All @@ -56,13 +56,15 @@ def __init__(self, instance):
self.edges = [] # [(i, j, EDGE_TYPE<JOIN|SPLIT>)]
self.sum_remaining = sum(instance) # sum of all numbers still unassigned
self.kk_sol = None
self.kk_score = 0

def copy(self):
clone = mcts.State.copy(self)
clone.labels = list(self.labels)
clone.edges = list(self.edges)
clone.sum_remaining = self.sum_remaining
clone.kk_sol = self.kk_sol
clone.kk_score = self.kk_score
return clone

def actions(self):
Expand All @@ -79,6 +81,7 @@ def apply(self, edge_type):
if edge_type == SPLIT:
insort(labels, (n-m, i))
self.sum_remaining -= 2 * m
self.kk_score += 1 # we've taken a KK decision, increment KK score
else:
insort(labels, (n+m, i))

Expand Down Expand Up @@ -130,13 +133,8 @@ def _assign_subset(adj, subset, i, s):
_assign_subset(adj, subset, j, s_j)


mcts.utils.config_logging()
r = NppTreeNode(NppState("instances/npp/hard0100.dat"))
s = mcts.Solver(r)


if __name__ == "__main__":
i = "instances/npp/hard1000.dat"
i = "instances/npp/hard0100.dat"
t = 60.0
if len(sys.argv) > 1:
i = sys.argv[1]
Expand Down
2 changes: 1 addition & 1 deletion src/rr/opt/mcts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def config_logging(name="rr.opt.mcts", level="INFO"):
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s',
'format': '[%(levelname)s] %(name)s: %(message)s',
},
},
'handlers': {
Expand Down

0 comments on commit 83c2609

Please sign in to comment.