Beispiel #1
0
def problem_sol(name):
    n_courses, n_profs, prereq, knowledge = input_reader(name)

    course_list = list(range(n_courses))

    prof_list = knowledge

    neighbor_list = create_neibours(prereq, n_courses)

    prof_course = dict()
    for item in course_list:
        prof_course[item] = prof_list

    problem = csp.CSP(course_list, prof_course, neighbor_list, func)

    answer = csp.tree_csp_solver(problem)
    problem.display(answer)

    log = ''
    if answer is not None:
        for key, value in answer.items():
            log += str(key) + ' ' + str(prof_list.index(value)) + '\n'
            # print('course:', key, '->', 'prof:', prof_list.index(value) + 1, '->', 'knowledge:', value[key])
    else:
        log += 'no assignment'
        # print('no assignment')

    return log
Beispiel #2
0
def build_csp(puzzle):
    """
    Create a CSP object representing the puzzle.
    :param puzzle (dictionary): The dictionary keys are tuples
    (row, column) representing the filled puzzle squares and the values
    are the corresponding numbers assigned to these squares.
    :return: CSP object
    """
    return csp.CSP(createDomains(puzzle), createNeighbors(puzzle),
                   createConstraints)
Beispiel #3
0
def build_csp(puzzle):
    """
    Create a CSP object representing the puzzle.
    :param puzzle (dictionary): The dictionary keys are tuples
    (row, column) representing the filled puzzle squares and the values
    are the corresponding numbers assigned to these squares.
    :return: CSP object
    """
    cells = combine(numbers, numbers)
    domains = {
        cell: [int(puzzle[cell])] if cell in puzzle else list(range(1, 10))
        for cell in cells
    }
    neighbors = get_neighbors(cells)

    return csp.CSP(domains, neighbors, check_constraint)
Beispiel #4
0
def CourseScheduler():
    courses = "cs108 cs112 cs212 cs214 cs232 cs262 cs344".split()
    variables = courses
    professors = 'VanderLinden Norman, Adams, Bailey'.split()
    times = 'mwf900 mwf1030 tth1130 tth1230'.split()
    classrooms = 'nh253 sb382'.split()
    possibleValues = list(itertools.product(classrooms, professors, times))
    random.shuffle(possibleValues)
    domains = {}
    for course in variables:
        domains[course] = possibleValues
    #print(domains)
    neighbors = {}
    for course in variables:
        courseCopyList = variables[:]
        courseCopyList.remove(course)
        neighborList = courseCopyList
        neighbors[course] = neighborList
    #print(neighbors)

    def constraints(A, a, B, b):
        #print("A " + str(A))
        #print("a " + str(a))
        #print("B " + str(B))
        #print("b " + str(b))
        # Room has space for one class at a time
        one_class_per_room_per_time = True
        # Faculty teaches 1 ting per time slot
        one_faculty_per_time = True
        # Course is taught by only one professor
        one_faculty_per_class = True

        # If the course is the same
        if A == B:
            # Then the same prof should be teaching it
            one_faculty_per_class = a[1] == b[1]
        # if the time is the same, but the course is not the same
        if a[2] == b[2] and A != B:
            # The same prof can't be teaching both classes
            one_faculty_per_time = (a[1] != b[1])
        # if the room is the same, and the time is the same
        if a[0] == b[0] and a[2] == b[2]:
            # then the class should be the same (no two courses in the same room at the same time)
            one_class_per_room_per_time = (A == B)
        return one_faculty_per_class and one_faculty_per_time and one_class_per_room_per_time

    return csp.CSP(variables, domains, neighbors, constraints)
Beispiel #5
0
# }

neighbors = {
    'Borean Tundra': {'Scholozar Basin', 'Wintergrasp', 'Dragonblight'},
    'Dragonblight': {'Wintergrasp', 'Icecrown', 'Crystalsong', 'Zul Drak', 'Grizzly Hills'},
    'Wintergrasp': {'Borean Tundra', 'Scholozar Basin', 'Icecrown', 'Dragonblight'},
    'Scholozar Basin': {'Borean Tundra', 'Icecrown', 'Wintergrasp'},
    'Crystalsong': {'Icecrown', 'Dragonblight', 'Storm Peaks', 'Zul Drak'},
    'Icecrown': {'Scholozar Basin', 'Wintergrasp', 'Dragonblight', 'Crystalsong', 'Storm Peaks'},
    'Storm Peaks': {'Icecrown', 'Crystalsong', 'Zul Drak'},
    'Zul Drak': {'Storm Peaks', 'Crystalsong', 'Dragonblight', 'Grizzly Hills'},
    'Grizzly Hills': {'Zul Drak', 'Dragonblight', 'Howling Fjord'},
    'Howling Fjord': {'Grizzly Hills'}
}

def constraints(A, a, B, b):
    if A == B:      # e.g. NSW == NSW
        return True

    if a == b:      # e.g. WA = G and SA = G
        return False

    return True

myNorthrend = csp.CSP(variables, domains, neighbors, constraints)

myCSPs = [
    {'csp': myNorthrend,
     # 'select_unassigned_variable':csp.mrv,
     }
]
Beispiel #6
0
                string = 'K' + str(i) + str(j)
                sys.stdout.write(str(dic[string]) + " ")
            print()


if __name__ == '__main__':
    """Read first line from file"""
    with open(sys.argv[1], 'r') as f:
        size = int(f.readline())
        lines = f.readlines()[1:]

    f.close()

    kenken = KenKen(size, lines)

    game_kenken = csp.CSP(kenken.variables, kenken.domains, kenken.neighbors,
                          kenken.kenken_constraint)

    if sys.argv[2] == "BT":
        print("Using BT algorithm to solve the puzzle")
        print()
        kenken.display(csp.backtracking_search(game_kenken), size)
    elif sys.argv[2] == "BT+MRV":
        print("Using BT and MRV algorithms to solve the puzzle")
        print()
        kenken.display(
            csp.backtracking_search(game_kenken,
                                    select_unassigned_variable=csp.mrv), size)
    elif sys.argv[2] == "FC":
        print("Using FC algorithm to solve the puzzle")
        print()
        kenken.display(
Beispiel #7
0
def courses_scheduling():
    # Defines the variables and values.
    courses = 'cs108 cs112 cs212 cs214 cs232 cs262 cs344'.split()
    faculty = 'adams vanderlinden plantinga wieringa norman'.split()
    time_slots = 'mwf8:00-8:50 mwf9:00-9:50 mwf10:30-11:20 tth11:30-12:20 tth12:30-1:20'.split(
    )
    classrooms = 'nh253 sb382'.split()

    if debug:
        # Debug statements.
        print('\ncourses list:' + str(courses))
        print('faculty list:' + str(faculty))
        print('time_slots list:' + str(time_slots))
        print('classrooms list:' + str(classrooms))

    variables = courses
    values = faculty + time_slots + classrooms

    if debug:
        # Debug statements.
        print('\nMy variables: ' + str(variables))
        print('My values: ' + str(values))

    # Combine values into triplets for use as part of domain.
    value_triplets = []

    for faculty in faculty:
        for timeslots in time_slots:
            for classroom in classrooms:
                triplet = faculty + ' ' + timeslots + ' ' + classroom
                value_triplets.append(triplet)

    if debug:
        # Debug statement.
        print("\nContents of value_triplets: " + str(value_triplets) + "\n")

    # Defines the domain.
    domain = {}
    for var in variables:
        domain[var] = value_triplets

    if debug:
        # Debug statements.
        for key, value in domain.items():
            print("My domain key: " + key)
            print("My domain values: " + str(value))

    # Define neighbors of each variable.
    neighbors = csp.parse_neighbors(
        """cs108: cs112 cs212 cs214 cs232 cs262 cs344;
                cs112: cs108 cs212 cs214 cs232 cs262 cs344; 
                cs212: cs108 cs112 cs214 cs232 cs262 cs344; 
                cs214: cs108 cs112 cs212 cs232 cs262 cs344;
                cs232: cs108 cs112 cs212 cs214 cs262 cs344; 
                cs262: cs108 cs112 cs212 cs214 cs232 cs344; 
                cs344: cs108 cs112 cs212 cs214 cs232 cs262""")

    if debug:
        # Debug statements.
        print("\n\n")
        for key, value in neighbors.items():
            print("Neighbors Key:" + key)
            print("Neighbors Values: " + str(value))
    """
        The constraints are that:
            each course should be offered exactly once by the assigned faculty member.
            a faculty member can only teach one thing at a time.
            a room can only have one class at each time.
    """

    # Define the constraints on the variables.
    # FIXME - WTB more documentation for AIMA code.
    def scheduling_constraint(A, a, B, b):

        if debug:
            # Debug statement.
            print("\nvalue of A: " + A)
            print("value of B: " + B)
            print("value of a: " + a)
            print("value of b: " + b)

        # Split "a" and "b" from triplets into singlets to test for same'ness.
        a_split = str(a).split()
        b_split = str(b).split()

        if debug:
            # Debug statement.
            print("\na split contents: " + str(a_split))
            print("b split contents: " + str(b_split))

        # Important note: (faculty, timeslot, classroom) is the order of the split triplet!!!
        if a_split[0] == b_split[0] and a_split[1] == b_split[1]:
            return False
        if a_split[1] == b_split[1] and a_split[2] == b_split[2]:
            return False

        # If no constraint violations, return true.
        return True
        # raise Exception('error')

    return csp.CSP(variables, domain, neighbors, scheduling_constraint)
Beispiel #8
0
    'Lazio': ['Tuscany', 'Umbria', 'Abruzzo', 'Molise', 'Campania'],
    'Abruzzo': ['Marche', 'Lazio', 'Molise'],
    'Molise': ['Abruzzo', 'Lazio', 'Campania', 'Apulia'],
    'Campania': ['Lazio', 'Molise', 'Apulia', 'Basilicata'],
    'Apulia': ['Molise', 'Campania', 'Basilicata'],
    'Basilicata': ['Apulia', 'Campania', 'Calabria'],
    'Calabria': ['Basilicata'],
}

vars = domains.keys()
domains = {}
for v in vars:
    domains[v] = ['R', 'G', 'B', 'P', 'O', 'T', 'M']


def constraints(A, a, B, b):
    if A == B:  # e.g. NSW == NSW
        return True

    if a == b:  # e.g. WA = G and SA = G
        return False

    return True


myItalymap = csp.CSP(vars, domains, neighbors, constraints)

myCSPs = [{
    'csp': myItalymap,
    # 'select_unassigned_variable':csp.mrv,
}]
Beispiel #9
0
import scipy as sp


def classification(x, y, clf='lsvm'):
    if clf == 'lsvm': model = svm.SVC(kernel='linear')
    return ''


if __name__ == '__main__':
    raw = np.load('data/comp_iva/epo.npz', allow_pickle=True)
    data = raw['data']
    x = data[0]['x']
    y = data[0]['y']

    x0 = []
    x1 = []
    x2 = []
    x3 = []
    for i in range(len(y)):
        if y[i] == 0:
            x0.append(x[i])
        elif y[i] == 1:
            x1.append(x[i])
        elif y[i] == 2:
            x2.append(x[i])
        elif y[i] == 3:
            x3.append(x[i])

    abc = csp.CSP([x0, x1, x2, x3])
    pass
Beispiel #10
0
import constants
import csp
import sudoku
import time

# ==================================================================================================
# MAIN
# ==================================================================================================

# Displaying the sudoku before the resolution
print("Sudoku is:")
S = sudoku.Sudoku.getSudokuFromFile("sudoku/1.txt")
S.display()

# Resolving the sudoku and keeping track of time
print("Trying to solve it...\n")
elapsedTime = -time.time()
CSP = csp.CSP(S)
solvedSudoku = CSP.backtrackingSearch()
elapsedTime += time.time()

# Displaying the solution
print("Finished in ", elapsedTime, "s, ", sep="", end="")
if (solvedSudoku != constants.FAILURE):
    print("solved sudoku is:")
    solvedSudoku.display()
else:
    print("failed to solve the sudoku... :-(")
Beispiel #11
0
def constraints(A, a, B, b):
    if A == B:      # e.g. NSW == NSW
        return True

    if a == b:      # e.g. WA = G and SA = Gw
        return False

    return True

# swap comments bellow to swap between texas 3-color and 4 color map

#c2 = csp.CSP(v2, d2, n2, constraints)
#c2.label = 'Texas map'

c2 = csp.CSP(v3, d3, c3, constraints)
c2.label = '4 Color Map'

myCSPs = [
    {
        'csp' : c2,
        # 'csp2' : c3,
        # 'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
        # 'inference': csp.forward_checking,
    },
    {
        'csp' : c2,
        'select_unassigned_variable': csp.mrv,
        # 'csp2' : c3,
Beispiel #12
0
             'JS': ['SJ', 'QP', 'FX'],
             'PD': ['FX', 'MH', 'XH', 'HP', 'HK', 'YP'],
             'MH': ['XH', 'CN', 'FX', 'JD', 'QP', 'SJ'],
             'BS': ['YP', 'PT', 'JD', 'ZB', 'HK'],
             }

def constraints(A, a, B, b):
    if A == B:      # e.g. NSW == NSW
        return True

    if a == b:      # e.g. WA = G and SA = G
        return False

    return True

c2 = csp.CSP(v2, d2, sh, constraints)
c2.label = 'Really Lame'

myCSPs = [
    {
        'csp' : c2,
        # 'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
        # 'inference': csp.forward_checking,
    },
    {
        'csp' : c2,
        'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
Beispiel #13
0
                        val = str(assignment[var])
                    print("%2s" % val, end=" ")
                print()
        else:
            print("no solution found")


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print(
            "Insufficient arguments passed. Sample usage:\npython kenken.py <path-to-input-file>"
        )
    filename = sys.argv[1]

    kenken = Kenken(filename)
    kenken_csp = csp.CSP(kenken.variables, kenken.domains, kenken.neighbors,
                         kenken.constraints)

    # 1. Basic backtracking
    print("1. Running basic backtracking ...")
    assignment1, node_count = csp.backtracking_search_with_assigment_count(
        kenken_csp)
    kenken.print_result(assignment1)
    print("(1) no. of assignments:", node_count)

    # 2. Improved backtacking: arc consistency (AC3) along with
    # minimum remaining heuristic and forward checking inference
    print("\n2. Improvement: AC3 along with mrv and forward_checking ...")

    # arc consistency AC3 algorithm as per text book.
    csp.AC3(kenken_csp)
    assignment2, node_count = csp.backtracking_search_with_assigment_count(
Beispiel #14
0
                    a[0][sample_x][col][row] = x_data[sample_x +
                                                      sample_y][col][row]
            sample_x += 1
        else:
            for col in range(240):
                for row in range(2):
                    a[1][sample_y][col][row] = x_data[sample_x +
                                                      sample_y][col][row]
            sample_y += 1
    return a


#print (b)
train_csp_raw = csp_data(train_x_data, train_y_data, 30)
test_csp_raw = csp_data(test_x_data, test_y_data, 15)
train_csp = csp.CSP(train_csp_raw)
test_csp = csp.CSP(test_csp_raw)

train_x_data = train_csp
test_x_data = test_csp

train_x_data = train_x_data.reshape(train_x_data.shape[0], 480, 1,
                                    1).astype(np.float32)
test_x_data = test_x_data.reshape(test_x_data.shape[0], 480, 1,
                                  1).astype(np.float32)

#train_x_data = train_x_data.reshape(train_x_data.shape[0], 480, 1, 1).astype(np.float32)
#test_x_data = test_x_data.reshape(test_x_data.shape[0], 480, 1, 1).astype(np.float32)

#train_x_data = train_x_data.reshape(train_x_data.shape[0], train_x_data.shape[1], train_x_data.shape[2], 1).astype(np.float32)
#test_x_data = test_x_data.reshape(test_x_data.shape[0], test_x_data.shape[1], test_x_data.shape[2], 1).astype(np.float32)
Beispiel #15
0
variables = provinces.keys()

domains = {}
for v in variables:
    domains[v] = ['R', 'G', 'B', 'Y']

def constraints(A, a, B, b):
    if A == B:      # e.g. NSW == NSW
        return True

    if a == b:      # e.g. WA = G and SA = G
        return False

    return True

colorChina = csp.CSP(variables, domains, provinces, constraints)
colorChina.label = 'China'
myCSPs = [
     {
        'csp' : colorChina,
        # 'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
        # 'inference': csp.forward_checking,
    },
    {
        'csp' : colorChina,
        'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
        # 'inference': csp.forward_checking,
Beispiel #16
0
      'B': ['A', 'C', 'D'],
      'C': ['A', 'B'],
      'D': ['A', 'B']}


def constraints(A, a, B, b):
    if A == B:      # e.g. NSW == NSW
        return True

    if a == b:      # e.g. WA = G and SA = G
        return False

    return True


c2 = csp.CSP(v2, d2, n2, constraints)
c2.label = 'Really Lame'

colors = ['R', 'G', 'B', 'Y']

domains = {
    'Riften': colors,
    'Eastmarch': colors,
    'Falkreath': colors,
    'Whiterun': colors,
    'Winterhold': colors,
    'ThePale': colors,
    'Markarth': colors,
    'Solitude': colors,
    'Morthal': colors
}
    "NT",
    "SA",
    "Q",
    "NSW",
    "V",
    "T",
]

# Domains
domains = {var: ["red", "green", "blue"] for var in variables}

# Neighbors
neighbors = {
    "WA": ["SA", "NT"],
    "NT": ["WA", "SA", "Q"],
    "SA": ["WA", "NT", "Q", "NSW", "V"],
    "Q": ["NT", "SA", "NSW"],
    "NSW": ["Q", "SA", "V"],
    "V": ["SA", "NSW"],
    "T": []
}


def constraintFunc(var1, val1, var2, val2):
    return var2 not in neighbors[var1] or val1 != val2


problem = csp.CSP(variables, domains, neighbors, constraintFunc)

# print(csp.backtracking_search(problem))
print(csp.min_conflicts(problem, 100000))
Beispiel #18
0
        'RetailRow'    :   ['WailingWoods', 'DustyDivot', 'SaltySprings', 'LonleyLodge'],
        'LonleyLodge'  :   ['WailingWoods', 'RetailRow', 'SaltySprings', 'ParadisePalms'],
        'ParadisePalms':   ['LonleyLodge', 'SaltySprings', 'FatalFields', 'FlushFactory'],
      }


def constraints(A, a, B, b):
    if A == B:      # e.g. NSW == NSW
        return True

    if a == b:      # e.g. WA = G and SA = G
        return False

    return True

fortnite = csp.CSP(v2, d2, n2, constraints)
fortnite.label = 'Fortnite'

myCSPs = [
    {
        'csp' : fortnite,
        # 'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
        # 'inference': csp.forward_checking,
    },
    {
        'csp' : fortnite,
        'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
Beispiel #19
0
    ],
    'I8': [
        'I1', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', 'I9', 'A8', 'C8', 'D8', 'E8',
        'F8', 'G8', 'H8', 'B8', 'G7', 'G9', 'H7', 'H9'
    ],
    'I9': [
        'I1', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7', 'I8', 'A9', 'C9', 'D9', 'E9',
        'F9', 'G9', 'H9', 'B9', 'G7', 'G8', 'H7', 'H8'
    ],
}
# def eliminateVariables(variablesTD):
#     for x in variablesTD:
#         domains.pop(x)


def constraints(A, a, B, b):
    if A == B:  # ex: A1 == A1
        return True

    if a == b:  # ex: A1 == 1 while A2 == 1
        return False

    return True


solverMethod = csp.CSP(variables, domains, neighbors, constraints)

myCSPs = [{
    'csp': solverMethod,
    # 'select_unassigned_variable':csp.mrv,
}]
Beispiel #20
0
    #'Kagawa': ['Tokushima', 'Ehime'],
    #'Tokushima': ['Kagawa', 'Ehime', 'Kochi'],
    #'Ehime': ['Kagawa', 'Tokushima', 'Kochi'],
    #'Kochi': ['Ehime', 'Tokushima'],
    #'Fukuoka': ['Oita', 'Kumamoto', 'Saga'],
    #'Oita': ['Fukuoka', 'Kumamoto', 'Miyazaki'],
    #'Miyazaki': ['Oita', 'Kumamoto', 'Kagoshima'],
    #'Kagoshima': ['Miyazaki', 'Kumamoto'],
    #'Kumamoto': ['Kagoshima', 'Miyazaki', 'Oita', 'Fukuoka'],
    #'Saga': ['Nagasaki', 'Fukuoka'],
    #'Nagasaki': ['Saga']
}


def constraints(A, a, B, b):
    if A == B:  # e.g. NSW == NSW
        return True

    if a == b:  # e.g. WA = G and SA = G
        return False

    return True


myJap = csp.CSP(variables, domains, neighbors, constraints)

myCSPs = [{
    'csp': myJap,
    # 'select_unassigned_variable':csp.mrv,
}]
Beispiel #21
0
    'TG': ['M', 'K', 'S', 'T', 'KL'],
    'KL': ['TG', 'T']
}


def constraints(A, a, B, b):
    if A == B:  # e.g. NSW == NSW
        return True

    if a == b:  # e.g. WA = G and SA = G
        return False

    return True


c2 = csp.CSP(v2, d2, Lithuania, constraints)
c2.label = 'Lithuania Map'

myCSPs = [
    {
        'csp': c2,
        # 'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
        # 'inference': csp.forward_checking,
    },
    {
        'csp': c2,
        'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
Beispiel #22
0
import csp


def constraint(A, a, B, b):
    if (A == 't1' and B == 't3'):
        return (a > b)
    elif (B == 't1' and A == 't3'):
        return (b > a)
    elif (A == 't3' and B == 't4'):
        return (b > a)
    elif (B == 't3' and A == 't4'):
        return (a > b)
    elif (A == 't3' and B == 't5'):
        return (a > b)
    elif (B == 't3' and A == 't5'):
        return (b > a)
    elif (A == 't1' and B == 't2') or (A == 't2' and B == 't1'):
        return (abs(a - b) > 60)
    elif (A == 't2' and B == 't4') or (A == 't4' and B == 't2'):
        return (abs(a - b) > 60)
    else:
        print(A, a, B, b)


variables = ['t1', 't2', 't3', 't4', 't5']
domains = {var: [540, 600, 660] for var in variables}
domains['t4'] = [540, 660]
neighs = """t1: t2 t3;t2: t4;t4: t3;t3: t5"""
neighs = csp.parse_neighbors(neighs)
timecsp = csp.CSP(variables, domains, neighs, constraint)
Beispiel #23
0
      'B': ['A', 'C', 'D'],
      'C': ['A', 'B'],
      'D': ['A', 'B'], }


def constraints(A, a, B, b):
    if A == B:  # e.g. NSW == NSW
        return True

    if a == b:  # e.g. WA = G and SA = G
        return False

    return True


c2 = csp.CSP(v2, d2, n2, constraints)
c2.label = 'Really Lame'

colors = ['R', 'G', 'B', 'Y']

domains = {
    'Clatsop': colors, 'Columbia': colors, 'Multnomah': colors, 'Hood River': colors,
    'Wasco': colors, 'Sherman': colors, 'Gilliam': colors, 'Morrow': colors, 'Umatilla': colors,
    'Union': colors, 'Wallowa': colors, 'Tillamook': colors, 'Washington': colors, 'Clackamas': colors,
    'Wheeler': colors, 'Grant': colors, 'Baker': colors, 'Yamhill': colors, 'Marion': colors,
    'Jefferson': colors, 'Polk': colors, 'Lincoln': colors, 'Benton': colors, 'Linn': colors,
    'Deschutes': 'R', 'Crook': colors, 'Lane': colors, 'Douglas': colors, 'Coos': colors,
    'Curry': colors, 'Josephine': colors, 'Jackson': colors, 'Klamath': colors, 'Lake': colors,
    'Harney': colors, 'Malheur': colors
}
Beispiel #24
0
    'LOWER-SAXONY': [
        'HOLSTEIN', 'ANHALT', 'WESTFALEN', 'HESSEN', 'THURINGEN',
        'BRANDENBURG', 'VORPOMMERN'
    ],
    'HOLSTEIN': ['VORPOMMERN', 'LOWER-SAXONY'],
    'VORPOMMERN': ['BRANDENBURG', 'LOWER-SAXONY', 'HOLSTEIN'],
    'SAARLAND': ['RHEINLAND']
}


def constraints(A, a, B, b):
    if A == B:  # e.g. NSW == NSW
        return True

    if a == b:  # e.g. WA = G and SA = G
        return False

    return True


germany = csp.CSP(cities, colors, map, constraints)
germany.label = 'GERMANY'

myCSPs = [{
    'csp': germany,
    'select_unassigned_variable': csp.mrv,
    'order_domain_values': csp.lcv,
    # 'inference': csp.mac,
    'inference': csp.forward_checking,
}]
Beispiel #25
0
    ],
    'Dodge': ['Washington', 'Waukesha', 'Jefferson'],
}


def constraints(A, a, B, b):
    if A == B:  # e.g. NSW == NSW
        return True

    if a == b:  # e.g. WA = G and SA = G
        return False

    return True


c2 = csp.CSP(v2, d2, wisconsin2d, constraints)
c2.label = 'Really Lame'

myCSPs = [
    {
        'csp': c2,
        # 'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
        # 'inference': csp.forward_checking,
    },
    {
        'csp': c2,
        'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
Beispiel #26
0
}


def constraints(A, a, B, b):
    if A == B:  # e.g. NSW == NSW
        return True

    if a == b:  # e.g. WA = G and SA = G
        return False
    return True


# c2 = csp.CSP(v2, d2, n2, constraints)
# c2.label = 'Really Lame'

nigeria = csp.CSP(nigeria2v, nigeria2d, nigeria2, constraints)
nigeria.label = "Simplified Map of Nigeria"

myCSPs = [
    {
        'csp': nigeria,
        # 'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
        # 'inference': csp.forward_checking,
    },
    {
        'csp': nigeria,
        'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
Beispiel #27
0
    'C': ['BL', 'H'],
    'H': ['C', 'RB']
}


def constraints(A, a, B, b):
    if A == B:  # e.g. NSW == NSW
        return True

    if a == b:  # e.g. WA = G and SA = G
        return False

    return True


myAus = csp.CSP(variables, domains, neighbors, constraints)

domainsNWAfrica = {
    'WS': rgb,
    'Mor': rgb,
    'Alg': rgb,
    'Tun': rgb,
    'Maur': rgb,
    'Sen': rgb,
    'TheGam': rgb,
    'Gui-Bis': rgb,
    'Gui': rgb,
    'SieLeo': rgb,
    'Lib': rgb,
    'Cot': rgb,
    'Ghana': rgb,
Beispiel #28
0
    'WA': ['OR', 'ID'],
    'WI': ['MN', 'IA', 'MI', 'IL'],
    'WV': ['OH', 'KY', 'PA', 'MD', 'VA'],
    'WY': ['ID', 'UT', 'MT', 'SD', 'NE', 'CO'],
}

variables = neighbors.keys()

domains = {}
for v in variables:
    domains[v] = ['R', 'G', 'B', 'K']


def constraints(A, a, B, b):
    if A == B:  # e.g. NSW == NSW
        return True

    if a == b:  # e.g. WA = G and SA = G
        return False

    return True


colorUS = csp.CSP(variables, domains, neighbors, constraints)

myCSPs = [{
    'csp': colorUS,
    #'select_unassigned_variable': csp.mrv,
    #'order_domain_values': csp.lcv,
    'inference': csp.mac,
}]
Beispiel #29
0
    'G': ['N', 'B', 'C', 'SP', 'S'],
    'S': ['G']
}


def constraints(A, a, B, b):
    if A == B:  # e.g. NSW == NSW
        return True

    if a == b:  # e.g. WA = G and SA = G
        return False

    return True


c2 = csp.CSP(v2, d2, n2, constraints)
c2.label = 'Mexico Culinary Map'

myCSPs = [
    {
        'csp': c2,
        # 'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
        # 'inference': csp.forward_checking,
    },
    {
        'csp': c2,
        'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
Beispiel #30
0
      754 : [239, 305, 561, 863],
      561 : [754, 863, 772],
      772 : [561, 863, 407, 321],
      863 : [352, 407, 772, 561, 754, 239, 941, 813]
      }

def constraints(A, a, B, b):
    if A == B:      # e.g. NSW == NSW
        return True

    if a == b:      # e.g. WA = G and SA = G
        return False

    return True

FLAreaCodes = csp.CSP(v2, d2, n2, constraints)
FLAreaCodes.label = 'Florida Area Codes'

myCSPs = [
    {
        'csp' : FLAreaCodes,
        # 'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,
        # 'inference': csp.forward_checking,
    },
    {
        'csp' : FLAreaCodes,
        'select_unassigned_variable': csp.mrv,
        # 'order_domain_values': csp.lcv,
        # 'inference': csp.mac,