Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/AI-Project.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Project/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Project/.idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Project/alg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Project/back_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 97 additions & 0 deletions Project/backtracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from numpy import *
import time
import random

N = 0
states = list()
solutions_bkt = list()
output_solutions = list()
count = 0
counter = 1


def ok(q_dict: list, col: int, mp, wp):
for i in range(0, col):
if q_dict[col] == q_dict[i]:
return False

for i in range(0, col):
if q_dict[col] == q_dict[i]:
return False

for i in range(0, col):
if (mp[i][q_dict[col]] < mp[i][q_dict[i]]) and (wp[q_dict[col]][i] < wp[q_dict[col]][col]):
return False
if (mp[col][q_dict[i]] < mp[col][q_dict[col]]) and (wp[q_dict[i]][col] < wp[q_dict[i]][i]):
return False
return True


def show(q_dict):
global count
count += 1
for i in range(0, N):
for j in range(0, N):
if q_dict[i] == j:
print("Man ", i, " is matched with woman ", j)


def get_state(q_dict, sol):
global count
state = dict()
count += 1
for i in range(0, N):
for j in range(0, N):
if q_dict[i] == j:
state[i] = j
return state, sol


def append_state(q_dict, sol):
global states
states.append((get_state(q_dict, sol)))


def append_to_output_possible_solutions(q_dict):
global output_solutions
global counter
state = dict()
counter += 1
for i in range(0, N):
for j in range(0, N):
if q_dict[i] == j:
state[str(i + 1)] = chr(ord('@') + j + 1)
# print(state)
output_solutions.append(state)


def move(q_dict, i, mp, wp):
# create state
if i == N:
append_state(q_dict, 1)
# print("q", q_dict)
solutions_bkt.append(get_state(q_dict, 1))
append_to_output_possible_solutions(q_dict)
# show(q_dict)
return
append_state(q_dict, 0)
for j in range(0, N):
q_dict[i] = j
if ok(q_dict, i, mp, wp):
move(q_dict, i + 1, mp, wp)


def bkt_approach(couples, mp, wp):
global N
N = couples
q = [0] * N

move(q, 0, mp, wp)
time.sleep(3)
return random.choice(output_solutions), 0


if __name__ == "__main__":
mp = array([[0, 2, 1], [0, 2, 1], [1, 2, 0]])
wp = array([[2, 1, 0], [0, 1, 2], [2, 0, 1]])
print(bkt_approach(3, mp, wp))
Binary file added Project/lines.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading