{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "VR in Space.ipynb", "provenance": [], "collapsed_sections": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "nBItk_gw7L2h" }, "source": [ "This model is for performing partial fulfillment of the requirement for the Msc. Degree in Artificial Intelligance\n", "\n", "Student Name: Ali Baqheri - c1963244\n", "\n", "Supervisor: Dr. Alia Abdelmoty\n", "\n", "\n", "Please follow the execution process in order to perform the reasoning task successfully." ] }, { "cell_type": "code", "metadata": { "id": "upBrMgv_Yfn8" }, "source": [ "# ------------------------ This part should run first --------------------------\n", "# ------------------------------------------------------------------------------\n", "# This part of the model includes all initializations and library imports needed.\n", "# All function definitions are also included here \n", "# The remaining parts of the model should be executed in the same order presented for smooth execution\n", "# During patruring inputs, if for any reason a correction is needed, please re-run that particular portion only\n", "\n", "from array import *\n", "import numpy as np\n", "\n", "\n", "# This function uses the number of elements per object as an argument to decide on how many elements is going to be captured\n", "\n", "def capture_input(ii):\n", " TX = [[4] * ii for i in range (ii)] #initialize matrix with dummy 4's\n", " xf = [[4] * ii for i in range (ii)] #initialize matrix with dummy 4's\n", " \n", " for i in range(ii):\n", " for j in range(ii):\n", " TX[i][j] = int(input(\"\"))\n", " if i == j:\n", " break\n", " for t in range(ii):\n", " xf[t] = [i for i in TX[t] if i != 4] # getting rid of the extra dummy 4's\n", " print(\"Object adjacency matrix: \")\n", " for i in range(ii):\n", " print(xf[i]) # printing out the collapsed version of the adjacency matrix \n", " return(xf)\n", "\n", "\n", "\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "d-Wf4WSE1OqS", "outputId": "5c02a061-41e4-449a-a948-ef0d6cca8a30", "colab": { "base_uri": "https://localhost:8080/", "height": 68 } }, "source": [ "# Capture number of elements per object (m, l, n)\n", "\n", "xcount = int(int(input(\"number of elements of object X:>> \")))\n", "ycount = int(int(input(\"number of elements of object Y:>> \")))\n", "zcount = int(int(input(\"number of elements of object Z:>> \")))" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "number of elements of object X:>> 3\n", "number of elements of object Y:>> 4\n", "number of elements of object Z:>> 5\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "VOPp9bfDsOB8", "outputId": "d283e739-58d3-4831-d251-4fe121d8b377", "colab": { "base_uri": "https://localhost:8080/", "height": 204 } }, "source": [ "# The function call for capturing object x elements\n", "print(\"Please input the adjacency matrix for object x: \")\n", "TX0 = capture_input(xcount)" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "Please input the adjacency matrix for object x: \n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n", "Object adjacency matrix: \n", "[1]\n", "[0, 1]\n", "[1, 0, 1]\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "ED-dK3dcsP2h" }, "source": [ "# The function call for capturing object y elements\n", "print(\"Please input the adjacency matrix for object y: \")\n", "TY0 = capture_input(ycount)" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "nYqhG1E7sP41" }, "source": [ "# The function call for capturing object z elements\n", "print(\"Please input the adjacency matrix for object z: \")\n", "TZ0 = capture_input(zcount)" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "nGKSPKFb-xVt" }, "source": [ "# The loop captures intersection matrix between the elements of objects x and y\n", "flagg = 0\n", "Rxy = [[0] * ycount for i in range (xcount)] # initialize a 2D matrix\n", "print(\"Please input intersection matrix Rxy: \")\n", "for i in range(xcount):\n", " for j in range(ycount):\n", " print(\"x\" + repr(i) + \" y\"+ repr(j))\n", " Rxy[i][j] = int(input())\n", "\n", "# Displaying the captured matrix \n", "print(\"Intersection matrix Rxy: \") \n", "for i in Rxy:\n", " print(i)" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "iqiQSji8Yss5" }, "source": [ "# The loop captures intersection matrix between the elements of objects y and z\n", "\n", "Ryz = [[0] * zcount for i in range (ycount)] # initialize a 2D matrix\n", "print(\"Please input intersection matrix Rxy: \")\n", "for i in range(ycount):\n", " for j in range(zcount):\n", " print(\"y\" + repr(i) + \" z\"+ repr(j))\n", " Ryz[i][j] = int(input())\n", " \n", "# Displaying the captured matrix \n", "print(\"Intersection matrix Ryz: \") \n", "for i in Ryz:\n", " print(i)" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "xRWhTYLB77gM" }, "source": [ "All needed input has been captured now, and the reasoning process start\n" ] }, { "cell_type": "code", "metadata": { "id": "Y-O-i6fH76ge" }, "source": [ "# Function definitions for handling the positions of labels for the case of indefinite relations\n", "# A different representation has been used for the distrinction of labels, 6's indicates labels in rows, 8's indicates labels in columns\n", "\n", "# These two funtions take in the result matrix of reasoning part AND the position matrix as arguments, and returns updated matrix with the label positions\n", "# here we check the positions row by row\n", "def xyonesmax(Rxz,RMS): # passing as arguments result matrix and position indicator dictionary\n", " RM = RMS\n", " Rxx = copy.deepcopy(Rxz) # the copy function is used to keep a fresh copy of Rxz and avoid manipulating Rxz\n", "\n", " for t in range(len(RM)): # iterate through the position matrix and intersection matrix\n", " for i in range(len(Rxx)):\n", " a = 0\n", " for j in range(len(Rxx[0])): \n", " if RM[t][i][j] == 0: # if the position matrix value = 0, and result matrix is not (0 or 1), the value in this position is indefinite\n", " if Rxx[i][j] == 2:\n", " a += 1\n", " if a == 2: # fine out if this value is a '?' or a label, 2 values in a row means its a label\n", " for l in range(len(Rxx)): \n", " if RM[t][i][l] == 0:\n", " if Rxx[i][l] == 2:\n", " Rxx[i][l] = 6 # update the indefinite value with 6 to indicate its a label\n", " \n", " return(Rxx) # return the updated intersection matrix\n", "\n", "# here we check the positions column by column\n", "def yzonesmax(Rx2,RMS): # passing as arguments result matrix and position indicator dictionary\n", " RM = RMS\n", " Rxx = copy.deepcopy(Rx2)\n", " \n", " for t in range(len(RM)): # iterate through the position matrix and intersection matrix\n", " for i in range(len(Rxx[0])): \n", " a = 0\n", " for j in range(len(Rxx)): \n", " if RM[t][j][i] == 0: # if the position matrix value = 0, and result matrix is not (0 or 1), the value in this position is indefinite\n", " if Rxx[j][i] == 2:\n", " a += 1\n", " if a == 2: # fine out if this value is a '?' or a label, 2 values in a row means its a label \n", " for l in range(len(Rxx)):\n", " if RM[t][l][i] == 0:\n", " if Rxx[l][i] == 2:\n", " Rxx[l][i] = 8 # update the indefinite value with 8 to indicate its a label\n", " \n", " return(Rxx) # return the updated intersection matrix\n", "\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "Wn24QWNf8v69" }, "source": [ "# function definitions in this part are not related to the reasoning, but only related to manipulating the result matrix and generate possible combinations\n", "\n", "# find the count of distinctive elements in order to prepare for the combinations generation\n", "# this function only provides the count of indefinet elements in order to generate suitable number of combinations\n", "def find_comb(Rxz):\n", " c2 = 0\n", " six_count = 0\n", " e8_count = 0\n", " for i in range(len(Rxz)):\n", " for j in range(len(Rxz[0])):\n", " if Rxz[i][j] == 6:\n", " six_count += 1\n", " if Rxz[i][j] == 8:\n", " e8_count += 1\n", "\n", " comb = []\n", " comb_count = 0\n", " for i in Rxz:\n", " for j in i:\n", " if j == 2:\n", " c2 = 1\n", "\n", " return(c2,six_count,e8_count) # depending on the number of lables, there will be different number of combinations\n", "\n", "\n", "# this function handles Rxz where there are only indistinctions but no disjoints (no labels, only ?'s)\n", "def twos_only(Rxz):\n", " x = np.array(Rxz)\n", " v = (x==2).sum()*([0,1],) # 0/1 combinatios depending on the number of 2's representing ?'s\n", " twos = np.array(np.meshgrid(*v)).T.reshape(-1,(x==2).sum())\n", " results = []\n", " for i in twos:\n", " m = x.copy()\n", " m[m==2] = i\n", " results.append(m.tolist())\n", " return(results,len(results)) # all combinations are generated and returned along with the number of combinations\n", "\n", "\n", "\n", "# this functions handles Rxz where there are only labels but no indistinctive relations. only 1 pair of labels can be handled per row or column\n", "def six_seven(Rxz,label): \n", " import numpy as np\n", " x = np.array(Rxz)\n", " label1 = label\n", " six = [[0,1],[1,0],[1,1]] # possible comninations generated here\n", " results = []\n", " for i in six:\n", " for j in six:\n", " m = x.copy()\n", " m[m==label1] = j\n", " results.append(m.tolist())\n", " return(results,len(results)) # all combinations are generated and returned along with the number of combinations\n", "\n", "# this functions handles Rxz where there are only labels but no indistinctive relations. 2 pairs of labels can be handled per row or column\n", "def six_seven2(Rxz,label):\n", " import numpy as np\n", " x = np.array(Rxz)\n", " label1 = label\n", " six = [[0,0,0,0],[0,0,0,1],[0,0,1,0],[0,0,1,1],[0,1,0,0],[0,1,0,1],[0,1,1,0],[0,1,1,1],[1,0,0,0],[1,0,0,1],[1,0,1,0],[1,0,1,1],[1,1,0,0],[1,1,0,1],[1,1,1,0],[1,1,1,1]]\n", " results = []\n", " for i in six:\n", " for j in six:\n", " m = x.copy()\n", " m[m==label1] = j\n", " results.append(m.tolist())\n", " return(results,len(results)) # all combinations are generated and returned along with the number of combinations\n", "\n", "\n", "# this function handles Rxz where there are labels and indefinite relations, only 1 pair of labels considered here\n", "def twos_labels(Rxz,label):\n", " import numpy as np\n", " x = np.array(Rxz)\n", " sevens = [[0,1],[1,0],[1,1]] # possible comninations for label pairs generated here\n", " v = (x==2).sum()*([0,1],) # 0/1 combinatios depending on the number of 2's representing ?'s\n", " twos = np.array(np.meshgrid(*v)).T.reshape(-1,(x==2).sum())\n", " results = []\n", " for i in sevens:\n", " for j in twos:\n", " m = x.copy()\n", " m[m==label] = i\n", " m[m==2] = j\n", " results.append(m.tolist())\n", " return(results,len(results)) # all combinations are generated and returned along with the number of combinations\n", "\n", "# this function handles Rxz where there are labels and indefinite relations, 2 pairs of labels considered here\n", "def twos_labels2(Rxz,label):\n", " import numpy as np\n", " x = np.array(Rxz)\n", " sevens = [[0,0,0,0],[0,0,0,1],[0,0,1,0],[0,0,1,1],[0,1,0,0],[0,1,0,1],[0,1,1,0],[0,1,1,1],[1,0,0,0],[1,0,0,1],[1,0,1,0],[1,0,1,1],[1,1,0,0],[1,1,0,1],[1,1,1,0],[1,1,1,1]]\n", " v = (x==2).sum()*([0,1],)\n", " twos = np.array(np.meshgrid(*v)).T.reshape(-1,(x==2).sum())\n", " results = []\n", "\n", " for i in sevens:\n", " for j in twos:\n", " m = x.copy()\n", " m[m==label] = i\n", "\n", " m[m==2] = j\n", " results.append(m.tolist())\n", " return(results,len(results)) # all combinations are generated and returned along with the number of combinations\n", "\n", "\n", "\n", "# This function is to elemenate rows and column of 0's from the output combinations (second general constraint)\n", "# the function handles the elemination of duplicate combinations as well\n", "def remove_zeros(RR):\n", " index = [] # start by getting rid of duplicate matrices\n", " for i in RR:\n", " if i in index:\n", " pass\n", " else:\n", " index.append(i) \n", " results = index\n", " # first iterate over rows and elemenate relations with 0's \n", " results2 = [] #initialize temporary matrix to store after deleting relations with 0's in rows\n", " for i in results:\n", " count = 0\n", " id = 0\n", " for j in i:\n", " count = 0\n", " for t in j:\n", " if t == 0:\n", " count += 1\n", " \n", " if count == 3:\n", " id = 1\n", " if id != 1:\n", " results2.append(i) # only valid relations are captured\n", " # now iterate over columns and elemenate relations with 0's\n", " results3 = [] \n", " count2 = 0\n", " for j in range(len(results2)):\n", " count2 = 0\n", " id1 = 0\n", " for i in range(len(results2[0])):\n", " count2 = 0\n", " for t in range(len(results[0][0])):\n", " if results2[j][t][i] == 0:\n", " count2 += 1\n", " \n", " if count2 ==3:\n", " id1 = 1 \n", " if id1 != 1:\n", " results3.append(results2[j]) # only valid relations are captured\n", " return(results3) # a clean matrix is returned\n", "\n", "\n", "\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "aVU9DDODMtjd" }, "source": [ "# The following matrices are only defined for easy reference during testing phase\n", "# Important note: this part must run every time before the reasoning process in the next part in order to initialize the matrix values\n", "\n", "R1 = [[1, 1, 1],[1, 0, 0],[1, 0, 0]]\n", "R2 = [[1, 1, 1],[1, 1, 0],[1, 0, 0]]\n", "R3 = [[1, 0, 1],[1, 1, 0],[1, 0, 0]]\n", "R4 = [[1, 1, 1],[1, 1, 1],[1, 0, 0]]\n", "R5 = [[1, 0, 1],[1, 1, 1],[1, 0, 0]]\n", "R6 = [[1, 0, 0],[1, 1, 1],[1, 0, 0]]\n", "R7 = [[1, 0, 0],[1, 1, 1],[1, 0, 1]]\n", "R8 = [[1, 0, 0],[1, 1, 0],[1, 0, 1]]\n", "R9 = [[1, 0, 0],[1, 1, 1],[1, 1, 1]]\n", "R10 = [[1, 0, 0],[1, 1, 0],[1, 1, 1]]\n", "R11 = [[1, 0, 0],[1, 0, 0],[1, 1, 1]]\n", "R12 = [[1, 0, 0],[1, 0, 1],[1, 1, 1]]\n", "R13 = [[1, 0, 1],[1, 0, 1],[1, 1, 1]]\n", "R14 = [[1, 0, 1],[1, 1, 1],[1, 1, 1]]\n", "R15 = [[1, 0, 1],[1, 1, 1],[1, 0, 1]]\n", "R16 = [[1, 1, 1],[1, 1, 1],[1, 0, 1]]\n", "R17 = [[1, 1, 1],[1, 0, 1],[1, 1, 1]]\n", "R18 = [[1, 1, 1],[1, 0, 1],[1, 0, 1]]\n", "R19 = [[1, 1, 1],[1, 0, 1],[1, 0, 0]]\n", "\n", "D = [[1, 1, 1],[1, 0, 0],[1, 0, 0]]\n", "CT = [[1, 0, 0],[1, 0, 0],[1, 1, 1]]\n", "CV = [[1, 0, 0],[1, 1, 0],[1, 1, 1]]\n", "CB = [[1, 1, 1],[0, 1, 1],[0, 0, 1]]\n", "M = [[1, 1, 1],[1, 1, 0],[1, 0, 0]]\n", "I = [[1, 1, 1],[0, 0, 1],[0, 0, 1]]\n", "O = [[1, 1, 1],[1, 1, 1],[1, 1, 1]]\n", "E = [[1, 0, 0],[0, 1, 0],[0, 0, 1]]\n", "\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "X1IeF9VK8Xts" }, "source": [ "#Adding indefinite relations\n", "# The reasoning part starts here\n", "# A key point here is the values of Rxy and Ryz as they are the main input to the reasoning part\n", "# If inputs from the input section are considered, re-assignement to these values has to be faded out\n", "# If pre-assigned values from previous section are used for testing purpose, simply assign the values to Rxy and Ryz and compare the result with the relevant composition table\n", "\n", "import numpy as np\n", "import copy\n", "import itertools\n", "flag = 0 # flag initialization to define the direction of propagation based on values of m' and n'\n", "col = 0\n", "row = 0\n", "rejectcount = 0\n", "\n", "Rxy = CT\n", "Ryz = I\n", "\n", "\n", "RMS = {} # dictionay object initialization to be used for capturing the position of indefinecy\n", "Rxz = [[2] * (len(Ryz[0])) for i in range (len(Rxy))] # initialization of result matrix with dummy 2's\n", "Rxz[0][0] = 1 # the intersection between x0 and z0 is always 1 as per first constraint\n", "\n", "# Propagation of non-empty intersections (rule 1)\n", "for j in range(len(Rxy[0])): # start by counting m\n", " xyones = 0\n", " yzones = 0\n", " for i in range(len(Rxy)): \n", "\n", " xyones += Rxy[i][j] \n", " \n", " if xyones == 1: # m' = 1, hence start propagating non-empty intersections (propagate x' over all z')\n", " for l in range(len(Rxy)): \n", " if Rxy[l][j] == 1: # find were x' = 1\n", " row = l\n", " for k in range(len(Ryz[0])): # look for all z' values \n", " if Ryz[j][k] == 1: \n", " col = k\n", " Rxz[row][col] = 1 # propagatation completed\n", "\n", " else: # m' is not 1, so we count n'\n", " for k in range(len(Ryz[0])): \n", " yzones += Ryz[j][k] \n", " \n", " if yzones == 1: # n' = 1, hence start propatating non-empty intersection (propagate z' over all x')\n", " for l in range(len(Ryz[0])): \n", " if Ryz[j][l] == 1: # find were z' = 1\n", " col = l\n", "\n", " for l in range(len(Rxy)): # look for all x' values\n", " if Rxy[l][j] == 1: \n", " row = l\n", " Rxz[row][col] = 1 # propagation complete\n", "\n", " else: # m' > 1 & n' > 1 which means there are some indistinctive intersections\n", " \n", " Reject = [[2] * (len(Ryz[0])) for i in range (len(Rxy))] # initialize a dummy (rejection) matrix of 2's, equal to the size of the resulting intersection matrix\n", " if yzones == len(Ryz[0]): # check if m' = m, and n' = n, if true, we do nothing\n", " if xyones == len(Rxy): \n", " continue\n", " else: # n' = n but m' < m\n", " flag = 1 # update the flag to indicate this case\n", " for l in range(len(Ryz[0])): # loop through common elements intersecting with y' \n", " for row in range(len(Rxy)): \n", " if Rxy[row][j] == 1: \n", " Reject[row][l] = 0 # the position is found, now check if Rxz has a stronger result here or not\n", " RMS[rejectcount] = Reject # store the rejection matrix found\n", " Reject = [[2] * (len(Ryz[0])) for i in range (len(Rxy))] # reinitialize the rejection matrix with dummy 2's for next use\n", " rejectcount += 1 # update the position of rejection matrix to refer to it in the dictionary\n", " \n", " else: # m' = m but n' < n\n", " flag = 2 # update the flag to indicate this case\n", " if xyones == len(Rxy): # loop through common elements intersecting with y'\n", " for l in range(len(Rxy)): \n", " for col in range(len(Ryz[0])): \n", " if Ryz[j][col] == 1: \n", " Reject[l][col] = 0 # the position is found, now check if Rxz has a stronger result here or not \n", " RMS[rejectcount] = Reject # store the rejection matrix found\n", " Reject = [[2] * (len(Ryz[0])) for i in range (len(Rxy))] # reinitialize the rejection matrix with dummy 2's for next use\n", " rejectcount += 1 # update the position of rejection matrix to refer to it in the dictionary\n", "\n", " else: # both m' < m and n' < n\n", " flag = 3 # update the flag to indicate this case, in this case the process needs to be repeated twice\n", " for l in range(len(Ryz[0])): # first loop through the second matrix and find where will be indistictions\n", " if Ryz[j][l] == 1: \n", " col = l \n", " for row in range(len(Rxy)): # now loop through the first matrix and find the common intersections with y'\n", " if Rxy[row][j] == 1: \n", " Reject[row][col] = 0 # the positions found and are stored in the rejection matrix\n", " RMS[rejectcount] = Reject # store the regection matrix in the dictionary for later reference\n", " Reject = [[2] * (len(Ryz[0])) for i in range (len(Rxy))] # reinitialize the rejection matrix with dummy 2's for next use\n", " rejectcount += 1 # update the position of rejection matrix to refer to it in the dictionary\n", "# the same process will be repeated now but from the other way around\n", " for l in range(len(Rxy)): # loop through the first matrix and find where will be indistictions \n", " if Rxy[l][j] == 1: \n", " row = l \n", " for col in range(len(Ryz[0])): \n", " if Ryz[j][col] == 1: # now loop through the first matrix and find the common intersections with y'\n", " Reject[row][col] = 0 # the positions found and are stored in the rejection matrix\n", " RMS[rejectcount] = Reject # store the regection matrix in the dictionary for later reference \n", " Reject = [[2] * (len(Ryz[0])) for i in range (len(Rxy))] # reinitialize the rejection matrix with dummy 2's for next use\n", " rejectcount += 1 # update the position of rejection matrix to refer to it in the dictionary\n", "\n", "# Now the process of propagating non-emty relations is partially completed, as labels position assignements will be decided once propagation of ...\n", "# ... empty relations is completed\n", "\n", "# Propagating empty intersections (rule2)\n", "\n", "xyones = 0\n", "yzones = 0\n", "assistant = [0 for i in range(len(Ryz[0]))] # initialize an indicator list to keep track of common intersections\n", "\n", "for i in range(len(Rxy)): # loop through the first matrix and find m'\n", " xyones = 0\n", " yzones = 0\n", " for j in range(len(Rxy[0])): \n", " xyones += Rxy[i][j] \n", " if xyones < len(Rxy[0]): # m' must be < m in order to propagate empty intersections\n", " for j in range(len(Rxy[0])): # find common intersections \n", " if Rxy[i][j] == 1: \n", " for k in range(len(Ryz[0])): \n", " if Ryz[j][k] == 1: # once found, update indicator\n", " assistant[k] = 1 \n", " for k in range(len(assistant)): # now loop throug the indicator to identify the position of intersections, in order to take the complement\n", " if assistant[k] == 0: # check for the complement where the value is 0 \n", " Rxz[i][k] = 0 # propagate through Rxz \n", "for j in range(len(Ryz[0])): # repreat the process on the second matrix, first find n' \n", " xyones = 0\n", " yzones = 0\n", " for ii in range(len(Ryz)): \n", " xyones += Ryz[ii][j]\n", " if xyones < len(Ryz): # n' must be < n in order to propagate empty intersections\n", " for k in range(len(assistant)):\n", " assistant[k] = 0 # reinitialize the indicator list\n", " for I in range(len(Ryz)): \n", " if Ryz[I][j] == 1: # find common intersections\n", " for k in range(len(Ryz[0])): \n", " if Rxy[k][I] == 1: # once found, update the indicator \n", " assistant[k] = 1\n", " for k in range(len(assistant)): # now loop throug the indicator to identify the position of intersections, in order to take the complement\n", " if assistant[k] == 0: # check for the complement where the value is 0\n", " Rxz[k][j] = 0 # propagate through Rxz\n", "\n", "# The process of propagating empty relations is now completed\n", "# The next step is to find the positions where there are indistinctions in order to label them, and generate the output intersection matrix Rxz\n", "# For the case of (1 < m' < m) & (1 < n' < n) we create 2 result matrices as there are 2 combinations of labels\n", "\n", "Rxz_rows = [[2] * (len(Ryz[0])) for i in range (len(Rxy))]\n", "Rxz_cols = [[2] * (len(Ryz[0])) for i in range (len(Rxy))]\n", "\n", "if flag == 0: # no propagation of indefinite sets, but we might have indistictive elements (places with ?)\n", " Rxz = yzonesmax(Rxz,RMS) \n", "\n", "if flag == 1: # here z' = Z, therefore the labels will be distributed column-wise\n", " Rxz = yzonesmax(Rxz,RMS)\n", "\n", "if flag == 2: # here x' = X, therefore the labels will be distributed row-wise\n", " Rxz = xyonesmax(Rxz,RMS)\n", " \n", "if flag == 3: # labels will be distributed column-wise and row-wise and 2 matrices are generated\n", " Rxz_rows = xyonesmax(Rxz,RMS)\n", "\n", " Rxz_cols = yzonesmax(Rxz,RMS)\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "e08U5j7blGlp", "outputId": "be9597c2-ee3e-424f-8de2-365696c03aea", "colab": { "base_uri": "https://localhost:8080/", "height": 72 } }, "source": [ "# Print the resulting intersection matrix (Rxz)\n", "\n", "if flag == 3:\n", " print(\"Matrix 1\")\n", " for i in Rxz_rows:\n", " print(i)\n", " print(\"\\nMatrix 2\")\n", " for i in Rxz_cols:\n", " print(i)\n", "else:\n", " for i in Rxz:\n", " print(i)" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "[1, 2, 2]\n", "[2, 2, 2]\n", "[2, 2, 1]\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "JTyo_rEj8TH-" }, "source": [ "# To generate all possible combinations:\n", "if flag == 3:\n", " c2_rows,six_count_rows,e8_count_rows = (find_comb(Rxz_rows))\n", " c2_cols,six_count_cols,e8_count_cols = (find_comb(Rxz_cols))\n", "else:\n", " c2,six_count,e8_count = (find_comb(Rxz)) \n", " \n", "\n", "# First check is if no indefinite relations are propagated (no disjoints), and hence we only provide combinations where no distiction is given\n", "if flag == 0: \n", " results,results_count = twos_only(Rxz)\n", "\n", "# Check if indefinite propagation is row-wise or column-wise\n", "if flag == 1:\n", " if c2 == 1:\n", " if e8_count > 2:\n", " results,results_count = twos_labels2(Rxz,8) # if we have both disjoints, and indistictive combinations\n", " else:\n", " results,results_count = twos_labels(Rxz,8) \n", " else:\n", " results,results_count = six_seven(Rxz,8) # if we have only disjoints\n", "\n", "if flag == 2:\n", " if c2 == 1:\n", " if six_count > 2:\n", " results,results_count = twos_labels2(Rxz,6) # if we have both disjoints, and indistictive combinations\n", " else:\n", " results,results_count = twos_labels(Rxz,6)\n", " else:\n", " if six_count > 2:\n", " results,results_count = six_seven2(Rxz,6) # if we have only disjoints\n", " else:\n", " results,results_count = six_seven(Rxz,6)\n", "\n", "if flag == 3:\n", "\n", " if c2_rows == 1:\n", " if six_count_rows > 2:\n", " results_rows,results_count_rows = twos_labels2(Rxz_rows,6) # if we have both disjoints, and indistictive combinations\n", " else:\n", " results_rows,results_count_rows = twos_labels(Rxz_rows,6) \n", " if e8_count_cols > 2:\n", " results_cols,results_count_cols = twos_labels2(Rxz_cols,8)\n", " else: \n", " results_cols,results_count_cols = twos_labels(Rxz_cols,8)\n", " else:\n", " if six_count_rows > 2:\n", " results_rows,results_count_rows = six_seven2(Rxz_rows,6) # if we have only disjoints\n", " else:\n", " results_rows,results_count_rows = six_seven(Rxz_rows,6)\n", " if e8_count_cols > 2: \n", " results_cols,results_count_cols = six_seven2(Rxz_cols,8)\n", " else:\n", " results_cols,results_count_cols = six_seven(Rxz_cols,8)\n", " results = results_rows+results_cols \n", " " ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "IuAFMGQT-h6I", "outputId": "bfc31a24-e436-4448-b8a0-a46379af3633", "colab": { "base_uri": "https://localhost:8080/", "height": 1000 } }, "source": [ "# now we get rid of redundant combinations and remove intersections were there are all 0's in a any given row or column as it contradicts with second generl constraint\n", "new_results = remove_zeros(results)\n", "\n", "# now print the resulting combinations followed by number of combinations\n", "\n", "for i in new_results:\n", " print(i)\n" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "[[1, 1, 0], [1, 0, 0], [0, 0, 1]]\n", "[[1, 1, 1], [1, 0, 0], [0, 0, 1]]\n", "[[1, 0, 0], [0, 1, 0], [0, 0, 1]]\n", "[[1, 0, 1], [0, 1, 0], [0, 0, 1]]\n", "[[1, 1, 0], [0, 1, 0], [0, 0, 1]]\n", "[[1, 1, 1], [0, 1, 0], [0, 0, 1]]\n", "[[1, 0, 0], [1, 1, 0], [0, 0, 1]]\n", "[[1, 0, 1], [1, 1, 0], [0, 0, 1]]\n", "[[1, 1, 0], [1, 1, 0], [0, 0, 1]]\n", "[[1, 1, 1], [1, 1, 0], [0, 0, 1]]\n", "[[1, 1, 0], [0, 0, 1], [0, 0, 1]]\n", "[[1, 1, 1], [0, 0, 1], [0, 0, 1]]\n", "[[1, 1, 0], [1, 0, 1], [0, 0, 1]]\n", "[[1, 1, 1], [1, 0, 1], [0, 0, 1]]\n", "[[1, 0, 0], [0, 1, 1], [0, 0, 1]]\n", "[[1, 0, 1], [0, 1, 1], [0, 0, 1]]\n", "[[1, 1, 0], [0, 1, 1], [0, 0, 1]]\n", "[[1, 1, 1], [0, 1, 1], [0, 0, 1]]\n", "[[1, 0, 0], [1, 1, 1], [0, 0, 1]]\n", "[[1, 0, 1], [1, 1, 1], [0, 0, 1]]\n", "[[1, 1, 0], [1, 1, 1], [0, 0, 1]]\n", "[[1, 1, 1], [1, 1, 1], [0, 0, 1]]\n", "[[1, 1, 0], [1, 0, 0], [1, 0, 1]]\n", "[[1, 1, 1], [1, 0, 0], [1, 0, 1]]\n", "[[1, 0, 0], [0, 1, 0], [1, 0, 1]]\n", "[[1, 0, 1], [0, 1, 0], [1, 0, 1]]\n", "[[1, 1, 0], [0, 1, 0], [1, 0, 1]]\n", "[[1, 1, 1], [0, 1, 0], [1, 0, 1]]\n", "[[1, 0, 0], [1, 1, 0], [1, 0, 1]]\n", "[[1, 0, 1], [1, 1, 0], [1, 0, 1]]\n", "[[1, 1, 0], [1, 1, 0], [1, 0, 1]]\n", "[[1, 1, 1], [1, 1, 0], [1, 0, 1]]\n", "[[1, 1, 0], [0, 0, 1], [1, 0, 1]]\n", "[[1, 1, 1], [0, 0, 1], [1, 0, 1]]\n", "[[1, 1, 0], [1, 0, 1], [1, 0, 1]]\n", "[[1, 1, 1], [1, 0, 1], [1, 0, 1]]\n", "[[1, 0, 0], [0, 1, 1], [1, 0, 1]]\n", "[[1, 0, 1], [0, 1, 1], [1, 0, 1]]\n", "[[1, 1, 0], [0, 1, 1], [1, 0, 1]]\n", "[[1, 1, 1], [0, 1, 1], [1, 0, 1]]\n", "[[1, 0, 0], [1, 1, 1], [1, 0, 1]]\n", "[[1, 0, 1], [1, 1, 1], [1, 0, 1]]\n", "[[1, 1, 0], [1, 1, 1], [1, 0, 1]]\n", "[[1, 1, 1], [1, 1, 1], [1, 0, 1]]\n", "[[1, 0, 0], [1, 0, 0], [0, 1, 1]]\n", "[[1, 0, 1], [1, 0, 0], [0, 1, 1]]\n", "[[1, 1, 0], [1, 0, 0], [0, 1, 1]]\n", "[[1, 1, 1], [1, 0, 0], [0, 1, 1]]\n", "[[1, 0, 0], [0, 1, 0], [0, 1, 1]]\n", "[[1, 0, 1], [0, 1, 0], [0, 1, 1]]\n", "[[1, 1, 0], [0, 1, 0], [0, 1, 1]]\n", "[[1, 1, 1], [0, 1, 0], [0, 1, 1]]\n", "[[1, 0, 0], [1, 1, 0], [0, 1, 1]]\n", "[[1, 0, 1], [1, 1, 0], [0, 1, 1]]\n", "[[1, 1, 0], [1, 1, 0], [0, 1, 1]]\n", "[[1, 1, 1], [1, 1, 0], [0, 1, 1]]\n", "[[1, 0, 0], [0, 0, 1], [0, 1, 1]]\n", "[[1, 0, 1], [0, 0, 1], [0, 1, 1]]\n", "[[1, 1, 0], [0, 0, 1], [0, 1, 1]]\n", "[[1, 1, 1], [0, 0, 1], [0, 1, 1]]\n", "[[1, 0, 0], [1, 0, 1], [0, 1, 1]]\n", "[[1, 0, 1], [1, 0, 1], [0, 1, 1]]\n", "[[1, 1, 0], [1, 0, 1], [0, 1, 1]]\n", "[[1, 1, 1], [1, 0, 1], [0, 1, 1]]\n", "[[1, 0, 0], [0, 1, 1], [0, 1, 1]]\n", "[[1, 0, 1], [0, 1, 1], [0, 1, 1]]\n", "[[1, 1, 0], [0, 1, 1], [0, 1, 1]]\n", "[[1, 1, 1], [0, 1, 1], [0, 1, 1]]\n", "[[1, 0, 0], [1, 1, 1], [0, 1, 1]]\n", "[[1, 0, 1], [1, 1, 1], [0, 1, 1]]\n", "[[1, 1, 0], [1, 1, 1], [0, 1, 1]]\n", "[[1, 1, 1], [1, 1, 1], [0, 1, 1]]\n", "[[1, 0, 0], [1, 0, 0], [1, 1, 1]]\n", "[[1, 0, 1], [1, 0, 0], [1, 1, 1]]\n", "[[1, 1, 0], [1, 0, 0], [1, 1, 1]]\n", "[[1, 1, 1], [1, 0, 0], [1, 1, 1]]\n", "[[1, 0, 0], [0, 1, 0], [1, 1, 1]]\n", "[[1, 0, 1], [0, 1, 0], [1, 1, 1]]\n", "[[1, 1, 0], [0, 1, 0], [1, 1, 1]]\n", "[[1, 1, 1], [0, 1, 0], [1, 1, 1]]\n", "[[1, 0, 0], [1, 1, 0], [1, 1, 1]]\n", "[[1, 0, 1], [1, 1, 0], [1, 1, 1]]\n", "[[1, 1, 0], [1, 1, 0], [1, 1, 1]]\n", "[[1, 1, 1], [1, 1, 0], [1, 1, 1]]\n", "[[1, 0, 0], [0, 0, 1], [1, 1, 1]]\n", "[[1, 0, 1], [0, 0, 1], [1, 1, 1]]\n", "[[1, 1, 0], [0, 0, 1], [1, 1, 1]]\n", "[[1, 1, 1], [0, 0, 1], [1, 1, 1]]\n", "[[1, 0, 0], [1, 0, 1], [1, 1, 1]]\n", "[[1, 0, 1], [1, 0, 1], [1, 1, 1]]\n", "[[1, 1, 0], [1, 0, 1], [1, 1, 1]]\n", "[[1, 1, 1], [1, 0, 1], [1, 1, 1]]\n", "[[1, 0, 0], [0, 1, 1], [1, 1, 1]]\n", "[[1, 0, 1], [0, 1, 1], [1, 1, 1]]\n", "[[1, 1, 0], [0, 1, 1], [1, 1, 1]]\n", "[[1, 1, 1], [0, 1, 1], [1, 1, 1]]\n", "[[1, 0, 0], [1, 1, 1], [1, 1, 1]]\n", "[[1, 0, 1], [1, 1, 1], [1, 1, 1]]\n", "[[1, 1, 0], [1, 1, 1], [1, 1, 1]]\n", "[[1, 1, 1], [1, 1, 1], [1, 1, 1]]\n" ], "name": "stdout" } ] } ] }