Exemplo n.º 1
0
def make_grid(size):
    response = requests.get("https://sugoku.herokuapp.com/board?difficulty=easy")
    values = response.json()['board']
    grid = []
    gap = (size[1] - WINDOW_GAP * 2) // ROWS
    for i in range(9):
        grid.append([])
        for j in range(9):
            node = nodeClass.Node(j, i, gap, values[j][i], 50)
            if node.get_value() != 0:
                node.set_isInitial(True)
            grid[i].append(node)
    return grid
Exemplo n.º 2
0
    def readResultLCMFile(self, result_lcm_file, low_sup, upper_sup):
        # Initialize re-constructed nodes
        for i in xrange(low_sup, upper_sup + 1):
            node = nodeClass.Node()
            self.frequent_list[self.getIndex(i)] = node

        # convert output of lcm_basic to item set list
        try:
            f = open(result_lcm_file, 'r')
            itemset_line = f.readline()
            transactions_line = ""
            while itemset_line:
                transactions_line = f.readline()
                # if line startswith space, this line is ignored
                if (itemset_line.startswith(" ")):
                    itemset_line = f.readline()
                    continue
                # convert output of lcm to item set list
                s = itemset_line[:-1].split(' ')
                transactions_line = transactions_line[1:]
                transactions = transactions_line[:-1].split(' ')
                # if itemset is not empty, add itemset to itemset_list
                if len(s) > 1:
                    itemset = set()
                    for i in range(0, len(s) - 1):
                        itemset.add(int(s[i]))
                    if transactions_line[:-1] == "":
                        transactions = []
                    else:
                        for i in range(0, len(transactions)):
                            transactions[i] = int(transactions[i])
                    support = len(transactions)
                    node = None
                    node_index = self.getIndex(support)
                    if (node_index < 0):
                        node = self.frequent_list[0]
                    else:
                        node = self.frequent_list[self.getIndex(support)]
                    node.addItemSet(tuple([itemset, transactions]))
                itemset_line = f.readline()
            f.close()
        except IOError, e:
            sys.stderr.write("%s" % e)
            sys.exit()
    def file_parser(self):
        with open('input.txt') as file:

            #placeholder for list of nodes
            nodes = []

            #read the algorithm type, string [BFS][UCS][A*]
            alg = (file.readline()).rstrip("\n")
            print('Using algorithm :\t {}'.format(alg))

            #read the bounding box integers x, y, and z
            bbox_dim = [int(s) for s in file.readline().split() if s.isdigit()]
            print('Dimension of maze is :\t {}x{}x{}'.format(
                bbox_dim[0], bbox_dim[1], bbox_dim[2]))

            #read the coordinate of the starting point (integers list)
            start_coord = [
                int(s) for s in file.readline().split() if s.isdigit()
            ]
            print('Start coordinate :\t ({}, {}, {})'.format(
                start_coord[0], start_coord[1], start_coord[2]))
            start_id = str(start_coord[0]) + '-' + str(
                start_coord[1]) + '-' + str(start_coord[2])

            #read the coordinate of the ending point (integers list)
            end_coord = [
                int(s) for s in file.readline().split() if s.isdigit()
            ]
            print('End coordinate :\t ({}, {}, {})'.format(
                end_coord[0], end_coord[1], end_coord[2]))
            end_id = str(end_coord[0]) + '-' + str(end_coord[1]) + '-' + str(
                end_coord[2])

            #read the next N lines of possible coords and actions
            num_lines = int(file.readline())
            for line in range(num_lines):
                vals = [int(s) for s in file.readline().split() if s.isdigit()]
                newNode = nodeClass.Node(vals[0], vals[1], vals[2], vals[3:])
                nodes.append(newNode)

        return alg, bbox_dim, start_id, end_id, nodes
Exemplo n.º 4
0
	def __init__(self, lcm_path, max_support, outlog):
		self.frequent_list = [] # index: max-support - support, In the list: Instance of Node class
		self.max_support = max_support # maximum value of the minimum support.
		self.constructed_index = -1 # frequent_list is constructed that its index is less than the value.
		self.outlog = outlog
	
		# Initialize the frequent_list.
		for i in xrange(0, self.max_support):
			self.frequent_list.append( nodeClass.Node() )
		
		# set LCM code path
		if lcm_path == None:
			current_dir = os.getcwd() # curent directory
			self.__LCMPATH = current_dir + "/lcm53/lcm"
			self.__LCMNAME = "lcm"
		else:
			self.__LCMPATH = lcm_path
			lcm_path_s = lcm_path.split("/")
			self.__LCMNAME = lcm_path_s[len(lcm_path_s) - 1]
		# check the LCM code exists
		if not (os.path.isfile(self.__LCMPATH)):
			sys.stderr.write("Please set lcm binary path with --lcm option\n")
			sys.exit()
Exemplo n.º 5
0
    def __init__(self, nsize, algorithm, grid):  # , movs=[]):
        """Initialize the n-puzzle problem, with n-size value, tsize the total nodes and initial the goal state from n.
        """

        self.__nsize = nsize
        self.__tsize = pow(self.__nsize, 2)
        self.__goal = range(0, self.__tsize)
        self.__algorithm = algorithm
        self.__grid = grid
        self.__pexpands = {}
        self.__cost_of_path = 0
        self.__final_node = nodeClass.Node()
        self.__start_time = time.time()
        self.__end_time = time.time()
        self.__initial_state = None

        if self.__algorithm == "bfs":
            self.__frontier = deque()
            self.__nodes = deque()  # Queue to show the final path
            self.__moves = [-self.__nsize, self.__nsize, -1, 1]
        elif self.__algorithm == "dfs":
            self.__frontier = deque()
            self.__nodes = deque()  # Queue to show the final path
            self.__moves = [1, -1, self.__nsize, -self.__nsize]
        elif self.__algorithm == "ast" or self.__algorithm == "ida":
            self.__frontier = priorityDict.PriorityDict()
            self.__nodes = dict()  # Queue to show the final path
            self.__moves = [-self.__nsize, self.__nsize, -1, 1]

        for key in range(self.__tsize):
            self.__pexpands[key] = self.getvalues(key)

        self.explored = set()

        self.__nodes_expanded = 0  # the number of nodes that have been expanded
        # self.max_fringe_size = 0 # the maximum size of the frontier set in the lifetime of the algorithm
        self.max_search_depth = 0  # the maximum depth of the search tree in the lifetime of the algorithm
Exemplo n.º 6
0
def new_node(depth, parent):
    x = nodeClass.Node()
    x.depth = depth
    x.parent = parent
    x.move = 0
    return x
Exemplo n.º 7
0
def child_node(parent, move):
    x = nodeClass.Node()
    x.depth = parent.depth + 1
    x.parent = parent
    x.move = move
    return x
Exemplo n.º 8
0
import nodeClass
from sklearn import datasets
import math
import random

iris = datasets.load_iris()

nodes = [nodeClass.Node() for count in xrange(5)]

irisD = iris.data.tolist()

#First Layer

#Weights are assigned
nodes[0].weights = [0.2, -0.3, 0.4, -0.9, 0.7]
nodes[1].weights = [0.3, -0.5, 0.7, 0.6, -0.6]

#Values are assigned
nodes[0].attribute = [-1] + irisD[0]
nodes[1].attribute = [-1] + irisD[0]  # Add Bias to front of values

nodes[0].value = nodes[0].math1()

nodes[1].value = nodes[1].math1()

nodes[0].activation = nodes[0].activator(nodes[0].value)

nodes[1].activation = nodes[1].activator(nodes[1].value)

#Second Layer
nodes[2]
Exemplo n.º 9
0
def node_object(random_x, random_y, dictionary):
    #create node obj for the nodes and store those in a dictionary
    for i in range(0, len(random_x)):
        dictionary[i] = nc.Node(random_x[i], random_y[i], i)