From cd6a2191f7688a008022f339ac0383e2018fad90 Mon Sep 17 00:00:00 2001 From: Tomek Date: Tue, 19 May 2020 12:20:50 +0200 Subject: [PATCH 01/10] sprwdzenie poprawnosci dzialania mojego lokalnego repozytorum --- route-planning.md | 1 - 1 file changed, 1 deletion(-) diff --git a/route-planning.md b/route-planning.md index ca850b4..a858ead 100644 --- a/route-planning.md +++ b/route-planning.md @@ -93,7 +93,6 @@ let winner = 0; let current = openSet[winner]; ``` - ### Definicja przyjętej heurystyki Jest to szacowana odległość od sprawdzanego pola do celu. Obliczana jest jako `Manhattan Distance`, ponieważ w naszym modelu Agent nie może poruszać się po skosie. From 537173bc70c795f4daee677aea9c69d11be728c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20=C5=81ukasik?= Date: Tue, 19 May 2020 13:14:19 +0200 Subject: [PATCH 02/10] dodanie decision tree --- .idea/workspace.xml | 31 +- Archiwum/frontend/js/main.js | 1132 +++++++++++----------- __pycache__/data.cpython-37.pyc | Bin 0 -> 1657 bytes __pycache__/decision_tree.cpython-37.pyc | Bin 0 -> 4767 bytes __pycache__/field.cpython-37.pyc | Bin 1367 -> 1383 bytes __pycache__/sweets.cpython-37.pyc | Bin 0 -> 471 bytes candy.py | 9 + data.py | 34 +- decision_tree.py | 184 ++++ field.py | 3 + main.py | 26 +- 11 files changed, 835 insertions(+), 584 deletions(-) create mode 100644 __pycache__/data.cpython-37.pyc create mode 100644 __pycache__/decision_tree.cpython-37.pyc create mode 100644 __pycache__/sweets.cpython-37.pyc create mode 100644 candy.py create mode 100644 decision_tree.py diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 95a134d..e7d3537 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,11 @@ - + - + + + + - + \ No newline at end of file diff --git a/Archiwum/frontend/js/main.js b/Archiwum/frontend/js/main.js index a0a8c6c..82a2d44 100644 --- a/Archiwum/frontend/js/main.js +++ b/Archiwum/frontend/js/main.js @@ -1,569 +1,569 @@ -//Klasy -class Agent{ - constructor(positionX, positionY, turn){ - this.positionX = positionX; - this.positionY = positionY; - this.turn = turn; - } - - getParams(){ - let params = {}; - - positionX = this.positionX; - positionY = this.positionY; - turn = this.turn; - - params = {positionX, positionY, turn}; - - return params; - } - - turnLeft(){ - if(this.turn == 'Up'){ - this.turn = 'Left'; - } - else if(this.turn == 'Down'){ - this.turn = 'Right'; - } - else if(this.turn == 'Left'){ - this.turn = 'Down'; - } - else if(this.turn == 'Right'){ - this.turn = 'Up' - } - } - - turnRight(){ - if(this.turn == 'Up'){ - this.turn = 'Right'; - } - else if(this.turn == 'Down'){ - this.turn = 'Left'; - } - else if(this.turn == 'Left'){ - this.turn = 'Up'; - } - else if(this.turn == 'Right'){ - this.turn = 'Down' - } - } - - showAgent(){ - if(this.turn === "Up"){ - document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = "url('img/Up.png')"; - } - else if(this.turn === "Down"){ - document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = "url('img/Down.png')"; - } - else if(this.turn === "Right"){ - document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = "url('img/Right.png')"; - } - else if(this.turn === "Left"){ - document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = "url('img/Left.png')"; - } - - } - - hideAgent(){ - document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = ""; - } - - goForward(){ - this.hideAgent() - if(this.turn == 'Up'){ - this.positionY += 1; - } - else if(this.turn == 'Down'){ - this.positionY -= 1; - } - else if(this.turn == 'Left'){ - this.positionX -= 1; - } - else if(this.turn == 'Right'){ - this.positionX += 1; - } - this.showAgent() - } - - goToField(field){ - if(field.yField > this.positionY){ - //pole jest nad agentem - - } - if(field.yField < this.positionY){ - //pole jest pod agentem - - } - if(field.xField > this.positionX){ - //pole jest na prawo - - } - if(field.xField < this.positionX){ - //pole jest na lewo - - } - } - - -} - -class Field{ - constructor(x, y, isShelf, isOccupiedByAgent, costOfTravel){ - this.xField = x; - this.yField = y; - this.isShelf = isShelf; - this.isOccupiedByAgent = isOccupiedByAgent; - this.costOfTravel = costOfTravel; - this.neighbors = []; - this.g = 0; - this.h = 0; - this.f = 0; - this.previous = undefined; - } - - getParams(){ - let params = {}; - - xField = this.xField; - yField = this.yField; - isShelf = this.isShelf; - isOccupiedByAgent = this.isOccupiedByAgent; - costOfTravel = this.costOfTravel; - params = {xField, yField, isShelf, isOccupiedByAgent, costOfTravel} - - return params; - } - - setIsShelf(isShelf){ - this.isShelf = isShelf; - } - - getIsShelf(){ - return this.isShelf; - } - - setIsOccupiedByAgent(isOccupiedByAgent){ - this.isOccupiedByAgent = isOccupiedByAgent; - } - - setCostOfTravel(costOfTravel){ - this.costOfTravel = costOfTravel; - } - - setNeighbors(field){ - if(field.isShelf == false){ - this.neighbors.push(field) - } - } -} - -class Shelf{ - constructor(accessY, accessX, havePlace, box1, box2, box3){ - this.accessX = accessX; - this.accessY = accessY; - this.havePlace = true; - this.box1 = box1; - this.box2 = box2; - this.box3 = box3; - } - - getParams(){ - let params = {}; - - xField = this.xField; - yField = this.yField; - havePlace = this.havePlace; - box1 = this.box1; - box2 = this.box2; - box3 = this.box3; - params = {xField, yField, havePlace, box1, box2, box3} - - return params; - } - - setbox1(box1){ - this.box1 = box1; - } - - setbox2(box1){ - this.box2 = box2; - } - - setbox3(box1){ - this.box3 = box3; - } - - setHavePlace(havePlace){ - this.havePlace = havePlace; - } -} - -class Candy{ - constructor(type, taste, mark, id){ - this.type = type; - this.taste = taste; - this.mark = mark; - this.id = id; - } - - getId(){ - return this.id; - } - -} - -//funkcje - -function createBoard(rangeX, rangeY){ - const board = []; - - for(let y = 0; y < rangeY; y++){ - const row = []; - for(let x = 0; x < rangeX; x++){ - let field = new Field(x, y, false, false, 1); - row.push(field) - } - board.push(row) - } - return board -} - -function createShelfOnBoard(board){ - //pierwszy poziom - board[2][2].setIsShelf(true); - board[3][2].setIsShelf(true); - - board[2][4].setIsShelf(true); - board[3][4].setIsShelf(true); - - board[2][6].setIsShelf(true); - board[3][6].setIsShelf(true); - - board[2][8].setIsShelf(true); - board[3][8].setIsShelf(true); - - //drugi poziom - board[5][2].setIsShelf(true); - board[5][3].setIsShelf(true); - - board[5][7].setIsShelf(true); - board[5][8].setIsShelf(true); - - //trzeci poziom - board[7][2].setIsShelf(true); - board[8][2].setIsShelf(true); - - board[7][4].setIsShelf(true); - board[8][4].setIsShelf(true); - - board[7][6].setIsShelf(true); - board[8][6].setIsShelf(true); - - board[7][8].setIsShelf(true); - board[8][8].setIsShelf(true); - return board -} - -function createCostofField(board, rangeX, rangeY){ - let cost; - let number; - for(let y = 0; y < rangeY; y++){ - for(let x = 0; x < rangeX; x++){ - number = 0; - if(y<9 && board[y+1][x].getIsShelf()){ - number = number + 1; - } - if(y>0 && board[y-1][x].getIsShelf()){ - number = number + 1; - } - if(x<9 && board[y][x+1].getIsShelf()){ - number = number + 1; - } - if(x>0 && board[y][x-1].getIsShelf()){ - number = number + 1; - } - cost = number*2; - if(cost==0){ - cost = 1; - } - board[y][x].setCostOfTravel(cost); - } - } - return board; -} - -function createShelf(){ - const listOfShelf = []; - - //pierwszy poziom - let shelf = new Shelf(2, 1, true, 211, 212, 0); - listOfShelf.push(shelf) - shelf = new Shelf(3, 1, true, 311, 0, 0); - listOfShelf.push(shelf) - - shelf = new Shelf(4, 4, false, 441, 442, 443); - listOfShelf.push(shelf) - shelf = new Shelf(1, 4, true, 0, 0, 0); - listOfShelf.push(shelf) - - shelf = new Shelf(4, 6, true, 461, 462, 0); - listOfShelf.push(shelf) - shelf = new Shelf(1, 6, true, 161, 0, 0); - listOfShelf.push(shelf) - - shelf = new Shelf(3, 9, true, 391, 0, 0); - listOfShelf.push(shelf) - shelf = new Shelf(2, 9, true, 291, 0, 0); - listOfShelf.push(shelf) - - //drugi poziom - shelf = new Shelf(5, 1, true, 511, 0, 0); - listOfShelf.push(shelf) - shelf = new Shelf(5, 4, true, 541, 0, 0); - listOfShelf.push(shelf) - - shelf = new Shelf(5, 6, true, 561, 0, 0); - listOfShelf.push(shelf) - shelf = new Shelf(5, 9, true, 591, 0, 0); - listOfShelf.push(shelf) - - //trzeci poziom - shelf = new Shelf(7, 1, true, 711, 0, 0); - listOfShelf.push(shelf) - shelf = new Shelf(8, 1, true, 811, 0, 0); - listOfShelf.push(shelf) - - shelf = new Shelf(6, 4, true, 641, 0, 0); - listOfShelf.push(shelf) - shelf = new Shelf(9, 4, true, 941, 0, 0); - listOfShelf.push(shelf) - - shelf = new Shelf(6, 6, true, 661, 0, 0); - listOfShelf.push(shelf) - shelf = new Shelf(9, 6, true, 961, 0, 0); - listOfShelf.push(shelf) - - shelf = new Shelf(7, 9, true, 791, 0, 0); - listOfShelf.push(shelf) - shelf = new Shelf(8, 9, true, 891, 0, 0); - listOfShelf.push(shelf) - - - return listOfShelf; -} - -function showBoard(board){ - for(let y = board.length - 1; y >= 0 ; y--){ - document.getElementById("board").innerHTML += "
"; - - for(let x = 0; x < board[y].length; x++){ - if(board[y][x].getIsShelf()) - document.getElementById("row-" + y).innerHTML += "
" - else - document.getElementById("row-" + y).innerHTML += "
"+ board[y][x].costOfTravel + "
" - } - } -} - -function getDistance(field, goalField){ - // var a = field.xField - goalField.xField; - // var b = field.yField - goalField.yField; - // var c = Math.sqrt(a*a + b*b); - var d = Math.abs(field.xField - goalField.xField) + Math.abs(field.yField - goalField.yField) - return d -} - -function addNeighbors(board){ - for(var y = 0; y < 10; y++){ - for(var x = 0; x < 10; x++){ - var leftNeigbor, rightNeighbor, topNeighbor, bottomNeighbor; - if(x > 0){ - leftNeigbor = board[y][x - 1]; - board[y][x].setNeighbors(leftNeigbor); - } - if(x < board[y].length - 1){ - rightNeighbor = board[y][x + 1]; - board[y][x].setNeighbors(rightNeighbor); - } - if(y > 0){ - bottomNeighbor = board[y - 1][x]; - board[y][x].setNeighbors(bottomNeighbor); - } - if(y < board.length - 1){ - topNeighbor = board[y + 1][x]; - board[y][x].setNeighbors(topNeighbor); - } - } - } -} - -// function colorGreen(field){ -// document.getElementById(field.xField + "-" + field.yField).style.backgroundColor = "green"; +// //Klasy +// class Agent{ +// constructor(positionX, positionY, turn){ +// this.positionX = positionX; +// this.positionY = positionY; +// this.turn = turn; +// } +// +// getParams(){ +// let params = {}; +// +// positionX = this.positionX; +// positionY = this.positionY; +// turn = this.turn; +// +// params = {positionX, positionY, turn}; +// +// return params; +// } +// +// turnLeft(){ +// if(this.turn == 'Up'){ +// this.turn = 'Left'; +// } +// else if(this.turn == 'Down'){ +// this.turn = 'Right'; +// } +// else if(this.turn == 'Left'){ +// this.turn = 'Down'; +// } +// else if(this.turn == 'Right'){ +// this.turn = 'Up' +// } +// } +// +// turnRight(){ +// if(this.turn == 'Up'){ +// this.turn = 'Right'; +// } +// else if(this.turn == 'Down'){ +// this.turn = 'Left'; +// } +// else if(this.turn == 'Left'){ +// this.turn = 'Up'; +// } +// else if(this.turn == 'Right'){ +// this.turn = 'Down' +// } +// } +// +// showAgent(){ +// if(this.turn === "Up"){ +// document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = "url('img/Up.png')"; +// } +// else if(this.turn === "Down"){ +// document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = "url('img/Down.png')"; +// } +// else if(this.turn === "Right"){ +// document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = "url('img/Right.png')"; +// } +// else if(this.turn === "Left"){ +// document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = "url('img/Left.png')"; +// } +// +// } +// +// hideAgent(){ +// document.getElementById(this.positionX + "-" + this.positionY).style.backgroundImage = ""; +// } +// +// goForward(){ +// this.hideAgent() +// if(this.turn == 'Up'){ +// this.positionY += 1; +// } +// else if(this.turn == 'Down'){ +// this.positionY -= 1; +// } +// else if(this.turn == 'Left'){ +// this.positionX -= 1; +// } +// else if(this.turn == 'Right'){ +// this.positionX += 1; +// } +// this.showAgent() +// } +// +// goToField(field){ +// if(field.yField > this.positionY){ +// //pole jest nad agentem +// +// } +// if(field.yField < this.positionY){ +// //pole jest pod agentem +// +// } +// if(field.xField > this.positionX){ +// //pole jest na prawo +// +// } +// if(field.xField < this.positionX){ +// //pole jest na lewo +// +// } +// } +// +// // } - -// function colorRed(field){ -// document.getElementById(field.xField + "-" + field.yField).style.backgroundColor = "red"; -// } - -// function colorYellow(field){ -// document.getElementById(field.xField + "-" + field.yField).style.backgroundColor = "yellow"; -// } - -const colorFactory = color => (field, animationFrame) => { - const delay = animationFrame * 50 - console.log(delay) - setTimeout(() => { - document.getElementById(field.xField + "-" + field.yField).style.backgroundColor = color; - }, delay); - return ++animationFrame -} - -const colorYellow = colorFactory('yellow') -const colorGreen = colorFactory('green') -const colorRed = colorFactory('red') - -// function addNeighborsToOpenSet(set, neigbors){ -// for(x = 0; x < neigbors.length; x++){ -// set.push(neigbors[x]); -// colorGreen(neigbors[x]); +// +// class Field{ +// constructor(x, y, isShelf, isOccupiedByAgent, costOfTravel){ +// this.xField = x; +// this.yField = y; +// this.isShelf = isShelf; +// this.isOccupiedByAgent = isOccupiedByAgent; +// this.costOfTravel = costOfTravel; +// this.neighbors = []; +// this.g = 0; +// this.h = 0; +// this.f = 0; +// this.previous = undefined; +// } +// +// getParams(){ +// let params = {}; +// +// xField = this.xField; +// yField = this.yField; +// isShelf = this.isShelf; +// isOccupiedByAgent = this.isOccupiedByAgent; +// costOfTravel = this.costOfTravel; +// params = {xField, yField, isShelf, isOccupiedByAgent, costOfTravel} +// +// return params; +// } +// +// setIsShelf(isShelf){ +// this.isShelf = isShelf; +// } +// +// getIsShelf(){ +// return this.isShelf; +// } +// +// setIsOccupiedByAgent(isOccupiedByAgent){ +// this.isOccupiedByAgent = isOccupiedByAgent; +// } +// +// setCostOfTravel(costOfTravel){ +// this.costOfTravel = costOfTravel; +// } +// +// setNeighbors(field){ +// if(field.isShelf == false){ +// this.neighbors.push(field) +// } // } // } - -function addToClosedSet(set, field){ - set.push(field); - colorRed(field); -} - - -function addToOpenSet(set, field){ - set.push(field); - colorGreen(field); -} - -function calculateFScore(field, goalField){ - let fscore, distanceToGoal, costOfTravel; - distanceToGoal = getDistance(field, goalField); - costOfTravel = field.costOfTravel; - fscore = costOfTravel + distanceToGoal; - return fscore; -} - -function findLowestFScore(openSet, goalField){ - let bestField = openSet[0]; - for(var x = 1; x < openSet.length; x++){ - if(calculateFScore(openSet[x], goalField) < calculateFScore(bestField, goalField)){ - bestField = openSet[x]; - } - } - return bestField; -} - -function removeFromSet(openSet, promisingField){ - for(var x = openSet.length - 1; x >= 0; x--){ - if(openSet[x] == promisingField){ - openSet.splice(x,1); - } - } -} - -function aStar(startField, goalField){ - let closedSet = []; - let openSet = []; - var path; - let animationFrame = 0 - - // addToOpenSet(openSet, startField) - openSet.push(startField); - colorGreen(startField, animationFrame); - - while(openSet.length > 0){ - - // let current = findLowestFScore(openSet, goalField); - let winner = 0; - for(let i = 0; i < openSet.length; i++){ - if (openSet[i].f < openSet[winner].f){ - winner = i - } - } - - let current = openSet[winner]; - - if(current === goalField){ - path = [] - var temp = current; - path.push(temp); - while(temp.previous){ - path.push(temp.previous); - temp = temp.previous - } - console.log("A* COMPLETED"); - - for(var i = 0; i < path.length; i++){ - animationFrame = colorYellow(path[i], animationFrame); - } - return path; - } - - removeFromSet(openSet, current); - // addToClosedSet(closedSet, current); - closedSet.push(current); - animationFrame = colorRed(current, animationFrame); - - var neighbors = current.neighbors; - - for(var i = 0; i < neighbors.length; i++){ - var neighbor = neighbors[i]; - - if(!closedSet.includes(neighbor)){ - var tempG = current.g + neighbor.costOfTravel; - - if(openSet.includes(neighbor)){ - if(tempG < neighbor.g){ - neighbor.g = tempG; - } - } else { - neighbor.g = tempG; - // addToOpenSet(openSet, neighbor); - openSet.push(neighbor); - animationFrame = colorGreen(neighbor,animationFrame); - } - neighbor.h = getDistance(neighbor, goalField); - neighbor.f = neighbor.g + neighbor.h; - - neighbor.previous = current; - } - } - } -} - -function executePath(agent, path){ - -} - - -let board = createBoard(10,10); -board = createShelfOnBoard(board); -board = createCostofField(board, 10, 10); -let candy = new Candy('zelek', 'truskawkowy', 'Jumbo', 541); -let shelfs = createShelf(); -let agent = new Agent(0,0, 'Right'); - -addNeighbors(board); - -function delayedFunction(func, index, time) { - setTimeout(() => func(), time * index); -} - -function start(){ - showBoard(board); - - // for (let i = 0; i<9; i++) { - // delayedStep(agent, i); - // } - const path = aStar(board[0][0], board[9][9]); - // agent.showAgent(); - console.log(path.reverse()) -} - - - +// +// class Shelf{ +// constructor(accessY, accessX, havePlace, box1, box2, box3){ +// this.accessX = accessX; +// this.accessY = accessY; +// this.havePlace = true; +// this.box1 = box1; +// this.box2 = box2; +// this.box3 = box3; +// } +// +// getParams(){ +// let params = {}; +// +// xField = this.xField; +// yField = this.yField; +// havePlace = this.havePlace; +// box1 = this.box1; +// box2 = this.box2; +// box3 = this.box3; +// params = {xField, yField, havePlace, box1, box2, box3} +// +// return params; +// } +// +// setbox1(box1){ +// this.box1 = box1; +// } +// +// setbox2(box1){ +// this.box2 = box2; +// } +// +// setbox3(box1){ +// this.box3 = box3; +// } +// +// setHavePlace(havePlace){ +// this.havePlace = havePlace; +// } +// } +// +// class Candy{ +// constructor(type, taste, mark, id){ +// this.type = type; +// this.taste = taste; +// this.mark = mark; +// this.id = id; +// } +// +// getId(){ +// return this.id; +// } +// +// } +// +// //funkcje +// +// function createBoard(rangeX, rangeY){ +// const board = []; +// +// for(let y = 0; y < rangeY; y++){ +// const row = []; +// for(let x = 0; x < rangeX; x++){ +// let field = new Field(x, y, false, false, 1); +// row.push(field) +// } +// board.push(row) +// } +// return board +// } +// +// function createShelfOnBoard(board){ +// //pierwszy poziom +// board[2][2].setIsShelf(true); +// board[3][2].setIsShelf(true); +// +// board[2][4].setIsShelf(true); +// board[3][4].setIsShelf(true); +// +// board[2][6].setIsShelf(true); +// board[3][6].setIsShelf(true); +// +// board[2][8].setIsShelf(true); +// board[3][8].setIsShelf(true); +// +// //drugi poziom +// board[5][2].setIsShelf(true); +// board[5][3].setIsShelf(true); +// +// board[5][7].setIsShelf(true); +// board[5][8].setIsShelf(true); +// +// //trzeci poziom +// board[7][2].setIsShelf(true); +// board[8][2].setIsShelf(true); +// +// board[7][4].setIsShelf(true); +// board[8][4].setIsShelf(true); +// +// board[7][6].setIsShelf(true); +// board[8][6].setIsShelf(true); +// +// board[7][8].setIsShelf(true); +// board[8][8].setIsShelf(true); +// return board +// } +// +// function createCostofField(board, rangeX, rangeY){ +// let cost; +// let number; +// for(let y = 0; y < rangeY; y++){ +// for(let x = 0; x < rangeX; x++){ +// number = 0; +// if(y<9 && board[y+1][x].getIsShelf()){ +// number = number + 1; +// } +// if(y>0 && board[y-1][x].getIsShelf()){ +// number = number + 1; +// } +// if(x<9 && board[y][x+1].getIsShelf()){ +// number = number + 1; +// } +// if(x>0 && board[y][x-1].getIsShelf()){ +// number = number + 1; +// } +// cost = number*2; +// if(cost==0){ +// cost = 1; +// } +// board[y][x].setCostOfTravel(cost); +// } +// } +// return board; +// } +// +// function createShelf(){ +// const listOfShelf = []; +// +// //pierwszy poziom +// let shelf = new Shelf(2, 1, true, 211, 212, 0); +// listOfShelf.push(shelf) +// shelf = new Shelf(3, 1, true, 311, 0, 0); +// listOfShelf.push(shelf) +// +// shelf = new Shelf(4, 4, false, 441, 442, 443); +// listOfShelf.push(shelf) +// shelf = new Shelf(1, 4, true, 0, 0, 0); +// listOfShelf.push(shelf) +// +// shelf = new Shelf(4, 6, true, 461, 462, 0); +// listOfShelf.push(shelf) +// shelf = new Shelf(1, 6, true, 161, 0, 0); +// listOfShelf.push(shelf) +// +// shelf = new Shelf(3, 9, true, 391, 0, 0); +// listOfShelf.push(shelf) +// shelf = new Shelf(2, 9, true, 291, 0, 0); +// listOfShelf.push(shelf) +// +// //drugi poziom +// shelf = new Shelf(5, 1, true, 511, 0, 0); +// listOfShelf.push(shelf) +// shelf = new Shelf(5, 4, true, 541, 0, 0); +// listOfShelf.push(shelf) +// +// shelf = new Shelf(5, 6, true, 561, 0, 0); +// listOfShelf.push(shelf) +// shelf = new Shelf(5, 9, true, 591, 0, 0); +// listOfShelf.push(shelf) +// +// //trzeci poziom +// shelf = new Shelf(7, 1, true, 711, 0, 0); +// listOfShelf.push(shelf) +// shelf = new Shelf(8, 1, true, 811, 0, 0); +// listOfShelf.push(shelf) +// +// shelf = new Shelf(6, 4, true, 641, 0, 0); +// listOfShelf.push(shelf) +// shelf = new Shelf(9, 4, true, 941, 0, 0); +// listOfShelf.push(shelf) +// +// shelf = new Shelf(6, 6, true, 661, 0, 0); +// listOfShelf.push(shelf) +// shelf = new Shelf(9, 6, true, 961, 0, 0); +// listOfShelf.push(shelf) +// +// shelf = new Shelf(7, 9, true, 791, 0, 0); +// listOfShelf.push(shelf) +// shelf = new Shelf(8, 9, true, 891, 0, 0); +// listOfShelf.push(shelf) +// +// +// return listOfShelf; +// } +// +// function showBoard(board){ +// for(let y = board.length - 1; y >= 0 ; y--){ +// document.getElementById("board").innerHTML += "
"; +// +// for(let x = 0; x < board[y].length; x++){ +// if(board[y][x].getIsShelf()) +// document.getElementById("row-" + y).innerHTML += "
" +// else +// document.getElementById("row-" + y).innerHTML += "
"+ board[y][x].costOfTravel + "
" +// } +// } +// } +// +// function getDistance(field, goalField){ +// // var a = field.xField - goalField.xField; +// // var b = field.yField - goalField.yField; +// // var c = Math.sqrt(a*a + b*b); +// var d = Math.abs(field.xField - goalField.xField) + Math.abs(field.yField - goalField.yField) +// return d +// } +// +// function addNeighbors(board){ +// for(var y = 0; y < 10; y++){ +// for(var x = 0; x < 10; x++){ +// var leftNeigbor, rightNeighbor, topNeighbor, bottomNeighbor; +// if(x > 0){ +// leftNeigbor = board[y][x - 1]; +// board[y][x].setNeighbors(leftNeigbor); +// } +// if(x < board[y].length - 1){ +// rightNeighbor = board[y][x + 1]; +// board[y][x].setNeighbors(rightNeighbor); +// } +// if(y > 0){ +// bottomNeighbor = board[y - 1][x]; +// board[y][x].setNeighbors(bottomNeighbor); +// } +// if(y < board.length - 1){ +// topNeighbor = board[y + 1][x]; +// board[y][x].setNeighbors(topNeighbor); +// } +// } +// } +// } +// +// // function colorGreen(field){ +// // document.getElementById(field.xField + "-" + field.yField).style.backgroundColor = "green"; +// // } +// +// // function colorRed(field){ +// // document.getElementById(field.xField + "-" + field.yField).style.backgroundColor = "red"; +// // } +// +// // function colorYellow(field){ +// // document.getElementById(field.xField + "-" + field.yField).style.backgroundColor = "yellow"; +// // } +// +// const colorFactory = color => (field, animationFrame) => { +// const delay = animationFrame * 50 +// console.log(delay) +// setTimeout(() => { +// document.getElementById(field.xField + "-" + field.yField).style.backgroundColor = color; +// }, delay); +// return ++animationFrame +// } +// +// const colorYellow = colorFactory('yellow') +// const colorGreen = colorFactory('green') +// const colorRed = colorFactory('red') +// +// // function addNeighborsToOpenSet(set, neigbors){ +// // for(x = 0; x < neigbors.length; x++){ +// // set.push(neigbors[x]); +// // colorGreen(neigbors[x]); +// // } +// // } +// +// function addToClosedSet(set, field){ +// set.push(field); +// colorRed(field); +// } +// +// +// function addToOpenSet(set, field){ +// set.push(field); +// colorGreen(field); +// } +// +// function calculateFScore(field, goalField){ +// let fscore, distanceToGoal, costOfTravel; +// distanceToGoal = getDistance(field, goalField); +// costOfTravel = field.costOfTravel; +// fscore = costOfTravel + distanceToGoal; +// return fscore; +// } +// +// function findLowestFScore(openSet, goalField){ +// let bestField = openSet[0]; +// for(var x = 1; x < openSet.length; x++){ +// if(calculateFScore(openSet[x], goalField) < calculateFScore(bestField, goalField)){ +// bestField = openSet[x]; +// } +// } +// return bestField; +// } +// +// function removeFromSet(openSet, promisingField){ +// for(var x = openSet.length - 1; x >= 0; x--){ +// if(openSet[x] == promisingField){ +// openSet.splice(x,1); +// } +// } +// } +// +// function aStar(startField, goalField){ +// let closedSet = []; +// let openSet = []; +// var path; +// let animationFrame = 0 +// +// // addToOpenSet(openSet, startField) +// openSet.push(startField); +// colorGreen(startField, animationFrame); +// +// while(openSet.length > 0){ +// +// // let current = findLowestFScore(openSet, goalField); +// let winner = 0; +// for(let i = 0; i < openSet.length; i++){ +// if (openSet[i].f < openSet[winner].f){ +// winner = i +// } +// } +// +// let current = openSet[winner]; +// +// if(current === goalField){ +// path = [] +// var temp = current; +// path.push(temp); +// while(temp.previous){ +// path.push(temp.previous); +// temp = temp.previous +// } +// console.log("A* COMPLETED"); +// +// for(var i = 0; i < path.length; i++){ +// animationFrame = colorYellow(path[i], animationFrame); +// } +// return path; +// } +// +// removeFromSet(openSet, current); +// // addToClosedSet(closedSet, current); +// closedSet.push(current); +// animationFrame = colorRed(current, animationFrame); +// +// var neighbors = current.neighbors; +// +// for(var i = 0; i < neighbors.length; i++){ +// var neighbor = neighbors[i]; +// +// if(!closedSet.includes(neighbor)){ +// var tempG = current.g + neighbor.costOfTravel; +// +// if(openSet.includes(neighbor)){ +// if(tempG < neighbor.g){ +// neighbor.g = tempG; +// } +// } else { +// neighbor.g = tempG; +// // addToOpenSet(openSet, neighbor); +// openSet.push(neighbor); +// animationFrame = colorGreen(neighbor,animationFrame); +// } +// neighbor.h = getDistance(neighbor, goalField); +// neighbor.f = neighbor.g + neighbor.h; +// +// neighbor.previous = current; +// } +// } +// } +// } +// +// function executePath(agent, path){ +// +// } +// +// +// let board = createBoard(10,10); +// board = createShelfOnBoard(board); +// board = createCostofField(board, 10, 10); +// let candy = new Candy('zelek', 'truskawkowy', 'Jumbo', 541); +// let shelfs = createShelf(); +// let agent = new Agent(0,0, 'Right'); +// +// addNeighbors(board); +// +// function delayedFunction(func, index, time) { +// setTimeout(() => func(), time * index); +// } +// +// function start(){ +// showBoard(board); +// +// // for (let i = 0; i<9; i++) { +// // delayedStep(agent, i); +// // } +// const path = aStar(board[0][0], board[9][9]); +// // agent.showAgent(); +// console.log(path.reverse()) +// } +// +// +// diff --git a/__pycache__/data.cpython-37.pyc b/__pycache__/data.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..90788d557c53ca70d1a55bc79d69a7a29fff6fd0 GIT binary patch literal 1657 zcmb7^&u<$=6vub%-L)OtiPQ8)($FR}5Mo-FGzD5p+qh{|5NUo;BY{R1Fy0w9Td#M_ z>@KdY^hA5+UjT994?yaWF^%b-*3*fuYb?j|_cW4Y1~Zw(3asduti;AxnN?U7 zJPy0!32+VeNoWp%r(i$Kjfz??r;|`0N<`v{$N;PAwj@Vbhr=d}K&SZL(zX4WvIE&cVz$(Au<&@8{ z74Z4Y{yK8L0j{xg>`mA&WPB0)7I*>nOUU^)*vR-Y_;kis9MhR4d3Lp>)mIZ$_qrZi ztpVp@V5_Zqa#$ADb*!L*Ryf*SEkrw18&nIvH1Fzr+SmG?{tcRwdD6B#$AeZK@RX5F z#Z;c@QRh?-c*fZTzWO9P^bF6`b3KPs&yfQ$N3-v9?0{z)&78qG$N%lw(@?hAt=QP4 zG9YDp#Jj?yObmv^?9fp7#0n&5zU%z*{)3bEpX8gQv@fE>V9{vk{Jzxw>fvuwO;Qk! z6g_|F+<&6Pi_KAfb8$0^oM<|8slCu7))o&!kCS4D`qWp4l|1S*IrO_o+N0in(w|mI zIh0Y*rGu`L88&X`sN^TiF(vQtMUA>TF*(< z{@9}ZKKEHYN6OUmcBEjD9R|b<)Tn%?Ni`o&Ppw~Sx59|Iv<<~=4n_Og&Bn^|%5t00 zke=-ixO((*>HWvWup^uUywY8XH?j5!$y~eNq{)1s+COOMXU{6 zwo8*6YEx`=-4H_&5KBmuf)nc&=K=P{w&WtY1JP*w2A7gc(U8L4<&qR{(a$LNJREcz z_4o*lCWWmigo!3IDy_L5^*!PKir+jj-Vxir`y+5vyJm;(7kqwOj<~%m20VG1=5K|P z4mvnwIR75)jmFnhd;Z>+b~v?nm20bRpn&PWOgdg^JL9Uysq|gn`9uv%I#U056>vmc Zyxha&dHgD_p#>N5s^p6&D*FHb{0Y|RyFCB^ literal 0 HcmV?d00001 diff --git a/__pycache__/decision_tree.cpython-37.pyc b/__pycache__/decision_tree.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5b41fddbf90b73b53fd4046cff5d588de6ac5353 GIT binary patch literal 4767 zcmbVPO^@5g8J-!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rri%dL2ic!ii*}f@y*UXZsV`ibl3ug2kk@G2lb)ddqo96_ z&HE^aml3jb8&+@Qr)aHYPuOnF;1FxXAYDhmmS*rQrK!eDa2DUD8J(P36mw?Cxbz-z z*l%EG6GAaC#(uqK9$B*&YuYlbjehe(?GRbsdimvB&PPaXZsfvo@-_|Mqm<}IucZj# zw2Vq?tPqXV>oh?*q!tOe6=o};)k2}$W(|2pRWh?0_X;10qYpu8j0I!3ht6Wz6bFJrJp_vP~i zd&s_|J9C%J7&)`h`E!>dAIuZiPe^Yk*iRL`gN#9EIFNp_nW~pCb&Qy~3L*g2LoC3a^{8>*;6Ig$=7 zN4!V7F&Vekofd-r?h!(3SS;iI@1~F-wsW~Zn1(mlr;^Q;(GE3s)*??M#RVK$U$xp6i ziqsGSa*ITPgeGH=1c(hX5<*A;S-04daxzPDQ&l$qV#;IG0;#ygnv|bdl!C61H!&q8 zJ})&hJtHZg6AVLX5AdCjHK;{=Q0SOi$E(W=agNZ|qgBdKQ$y6i= MlgH3F*`8Gb06xu6X#fBK delta 320 zcmaFPb)AdXiIW=jABp8(@XEDi7?q&+t5CkeN5&;sLj78!gHb^&wkOZ=Bu_fhXmgJ@? zZsuanW7GnvxW$^3pIDTFu8=n|B_%#DH8VXUDZi*#W%44H&oe9MT-jU@=XmA_15@hQ`VMtP%i4Lqz%j diff --git a/__pycache__/sweets.cpython-37.pyc b/__pycache__/sweets.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c1890e13459b48e17170ea71c4e4c1cde2d78a98 GIT binary patch literal 471 zcmYk2%}N6?5XY132Wzni;uDCMJy=SQB2quVixi;;VOb2zCczxMx=W}%1ZrM0$!Y=eIsio- zf count + + for row in rows: + name = row[-1] + if name not in counts: + counts[name] = 0 + counts[name] += 1 + return counts + + +# funkcja do sprawdzania czy wartość jest wartością numeryczną +def is_numeric(val): + return isinstance(val, int) or isinstance(val, float) + + +# klasa do zadawania pytań +class Question: + def __init__(self, column, value): + self.column = column + self.value = value + + def match(self, example): + val = example[self.column] + + if is_numeric(val): + return val >= self.value + else: + return val == self.value + + def __repr__(self): + condition = '==' + if is_numeric(self.value): + condition = '>=' + return "Is %s %s %s?" % (header[self.column], condition, str(self.value)) + + +def partition(rows, question): + """ podział zbioru informacji + dla każdego rzędu w zbiorze, sprawdź czy zgadza się z pytaniem, jeśli tak + dodaj do 'true' inaczej dodaj do 'false' """ + true_rows, false_rows = [], [] + for row in rows: + if question.match(row): + true_rows.append(row) + else: + false_rows.append(row) + return true_rows, false_rows + + +def gini(rows): + """ Gini impurity is a measure of how often a randomly chosen element from + the set would be incorrectly labeled if it was randomly labeled according to + the distribution of labels in the subset. """ + + counts = class_counts(rows) + impurity = 1 + for lbl in counts: + prob_of_lbl = counts[lbl] / float(len(rows)) + impurity -= prob_of_lbl ** 2 + return impurity + + +def info_gain(left, right, current_uncertainty): + p = float(len(left)) / (len(left) + len(right)) + return current_uncertainty - p * gini(left) - (1 - p) * gini(right) + + +def find_best_split(rows): + """ znajdź najlepsze możliwe pytanie do zadania, sprawdzając wszystkie + właściwośći oraz licząc dla nich 'info_gain' """ + best_gain = 0 + best_question = None + current_uncertainty = gini(rows) + n_features = len(rows[0]) - 1 + + for col in range(n_features): + values = set([row[col] for row in rows]) + + for val in values: + question = Question(col, val) + + true_rows, false_rows = partition(rows, question) + + if len(true_rows) == 0 or len(false_rows) == 0: + continue + + gain = info_gain(true_rows, false_rows, current_uncertainty) + + if gain > best_gain: + best_gain, best_question = gain, question + + return best_gain, best_question + + +class Leaf: + def __init__(self, rows): + self.predicions = class_counts(rows) + + +class DecisionNode: + def __init__(self, question, true_branch, false_branch): + self.question = question + self.true_branch = true_branch + self.false_branch = false_branch + + +def build_tree(rows): + gain, question = find_best_split(rows) + + if gain == 0: + return Leaf(rows) + + true_rows, false_rows = partition(rows, question) + + true_branch = build_tree(true_rows) + + false_branch = build_tree(false_rows) + + return DecisionNode(question, true_branch, false_branch) + + +def print_tree(node, spacing=""): + if isinstance(node, Leaf): + print(spacing + "Predict", node.predicions) + + else: + print(spacing + str(node.question)) + + print(spacing + '--> True:') + print_tree(node.true_branch, spacing + " ") + + print(spacing + '--> False:') + print_tree(node.false_branch, spacing + " ") + + +def classify(row, node): + if isinstance(node, Leaf): + return node.predicions + + if node.question.match(row): + return classify(row, node.true_branch) + else: + return classify(row, node.false_branch) + + +def print_leaf(counts): + probs = [] + for lbl in counts.keys(): + probs.append(lbl) + return probs + + +# my_tree = build_tree(training_data) +# +# print_tree(my_tree) +# +# testing_data = [ +# ['gold', 'rectangle', 50, 'medium', 'Name'], +# ['brown', 'rectangle', 55, 'medium', 'Snickers'], +# ['white', 'rectangle', 120, 'big', 'Name'] +# ] +# +# test = ['white', 'rectangle', 120, 'big', 'Name'] +# +# # for row in testing_data: +# # print(print_leaf(classify(row, my_tree))) +# +# wynik = print_leaf(classify(test, my_tree))[0] +# print(wynik) + diff --git a/field.py b/field.py index 033612c..99ade93 100644 --- a/field.py +++ b/field.py @@ -21,6 +21,9 @@ class Field: self.f = 0 self.previous = None + # Przedmiot, który podnosi agent + self.item = [] + # Te rzeczy są potrzebne do wyświetlenia pola self.image = pygame.image.load('img/Field.png') self.rect = self.image.get_rect() diff --git a/main.py b/main.py index 63bd66d..6a0a9cc 100644 --- a/main.py +++ b/main.py @@ -2,11 +2,13 @@ import pygame import functions import sys import time +import decision_tree +import data from agent import Agent from settings import Settings from board import create_board, draw_board -from random import randint +from random import randint, choice # Inicjalizacja programu i utworzenie obiektu ekrany @@ -17,10 +19,11 @@ def run(): pygame.display.set_caption("Inteligentny wózek widłowy") agent = Agent(screen, 50, 50, "Down") board = create_board(screen) + my_tree = decision_tree.build_tree(data.learning_data) - for row in board: - for field in row: - print(field.cost_of_travel) + # for row in board: + # for field in row: + # print(field.cost_of_travel) path = [] next_step = None @@ -41,7 +44,10 @@ def run(): agent.move_forward(board) print(agent.x, agent.y) elif event.key == pygame.K_SPACE: - field = board[randint(0, 9)][randint(0, 9)] + board[9][0].item = choice(data.learning_data) + print("Wybrano: " + board[9][0].item[-1]) + board[9][0].item[-1] = 'Something' + field = board[9][0] if not field.is_shelf: path = functions.a_star(board[agent.y][agent.x], field, board) path.pop(len(path) - 1) @@ -61,12 +67,14 @@ def run(): for field in row: if not field.is_shelf: field.image = pygame.image.load('img/Field.png') - for row in board: - for field in row: - print(field.g, field.h, field.f, field.previous) + else: functions.change_turn(agent, next_step) - print(agent.x, agent.y) + + if board[agent.y][agent.x].item: + prediction = decision_tree.print_leaf(decision_tree.classify(board[agent.y][agent.x].item, my_tree)) + print("Agent uważa, że przedmiot to: " + prediction[0]) + board[agent.y][agent.x].item = [] draw_board(board) agent.blitme() From 734505ab3db2ee0cb0a09ad8d9e6f3f36cb22639 Mon Sep 17 00:00:00 2001 From: Tomek Date: Tue, 19 May 2020 17:45:15 +0200 Subject: [PATCH 03/10] Dodanie podprojektu --- .idea/misc.xml | 2 +- .idea/wozek.iml | 2 +- __pycache__/agent.cpython-38.pyc | Bin 0 -> 1981 bytes __pycache__/board.cpython-38.pyc | Bin 0 -> 1475 bytes __pycache__/data.cpython-38.pyc | Bin 0 -> 2169 bytes __pycache__/decision_tree.cpython-38.pyc | Bin 0 -> 4825 bytes __pycache__/field.cpython-38.pyc | Bin 0 -> 1638 bytes __pycache__/functions.cpython-38.pyc | Bin 0 -> 2998 bytes __pycache__/mcda.cpython-38.pyc | Bin 0 -> 2384 bytes __pycache__/product.cpython-38.pyc | Bin 0 -> 475 bytes __pycache__/settings.cpython-38.pyc | Bin 0 -> 585 bytes __pycache__/shelf.cpython-38.pyc | Bin 0 -> 600 bytes __pycache__/supply.cpython-38.pyc | Bin 0 -> 1288 bytes __pycache__/sweets.cpython-38.pyc | Bin 0 -> 491 bytes main.py | 4 +- mcda.py | 100 +++++++++++++++++++++++ product.py | 7 ++ supply.py | 64 +++++++++++++++ 18 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 __pycache__/agent.cpython-38.pyc create mode 100644 __pycache__/board.cpython-38.pyc create mode 100644 __pycache__/data.cpython-38.pyc create mode 100644 __pycache__/decision_tree.cpython-38.pyc create mode 100644 __pycache__/field.cpython-38.pyc create mode 100644 __pycache__/functions.cpython-38.pyc create mode 100644 __pycache__/mcda.cpython-38.pyc create mode 100644 __pycache__/product.cpython-38.pyc create mode 100644 __pycache__/settings.cpython-38.pyc create mode 100644 __pycache__/shelf.cpython-38.pyc create mode 100644 __pycache__/supply.cpython-38.pyc create mode 100644 __pycache__/sweets.cpython-38.pyc create mode 100644 mcda.py create mode 100644 product.py create mode 100644 supply.py diff --git a/.idea/misc.xml b/.idea/misc.xml index 715ed69..adaa126 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/.idea/wozek.iml b/.idea/wozek.iml index a9742fc..904114b 100644 --- a/.idea/wozek.iml +++ b/.idea/wozek.iml @@ -4,7 +4,7 @@ - + diff --git a/__pycache__/agent.cpython-38.pyc b/__pycache__/agent.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7eee4502453830eb1bf743e3b70ea701838e2741 GIT binary patch literal 1981 zcmbVNPj4GV6rY)$U9ZJ>@Bhw^Y6g@b*NbQz9c%>63JYA2!crt$_;cut9@2CLdh{gie@Q$CX# zVE6WMLKekM#o(IXIsXJ_pDVzHOvi(dF671}AGB9YQ1*3_hS74(siM7Mn-%Ve~#Yj8k^ z1h_+{=}OO-ejTri4<3Bc-6<1YcDH(u6P*|RgYH&R4y$6){Z1EIGOW5dHLo@%M<$Hp zG*7EI4zRU+4ZwIX`?YvWT<1+5iQ`p!Asch!J}1N3AbD{!*D*o9*a@XfSl+T43C*^$Gf1eHxDow?zDWhl7UX5NMg$?)`NjC}TvX;WFQ+>oEaNWQ{xdvc7;^ER0 z@Z)PP0}I>#l>`d;jtg*>1Pb}yEG;exl&Ec&mj6hCev<-uo8T>iTLg;?=yzy(Rlt!A zLQ}$S!{%iXx0WKd#(i51*g=D2>R7fdWGF>@gLLmdKtk6UN=Q_UTzO~$-a5NUHt1#~ zW#~uFR$7bCL5OyOdd|?J>`XrAxnm7r`NHlc))#ZuOU60>j1{)v!AX_}Rfw5CWA*c2 zz{FGyoPS#H!Xbk+^AxpqwWqLko__WZPwh0i zYq=KQ+8Nb9G#R(eFoQcL^@P tW-Cz#(^Q<4my+6ZD8kjy3maj>>Jg%C3S@KDW)pttT=A3-E@OYt;Or-G@Bmx7g$5Y#i22luh);wsIAJTYCbn;LCdCo+IoRO5V7>z`)UbDf zKW1HTf$?mo%M0(Z%(7uTND(`ahBAUaCtvk>*l%Eah%J4Mo&n1_a1daTFo}W(E3gU| zpbiaa!Wyi@M{p4?!Ny=C7a7a=NF4EP_QP>*VYF=+%P?{7WVUA7(H30R4qVw_Er!Ud zPzzenKJs!`3yi;;*R(rwbPYNkHWum-M=p-q9&jvCMz+dpyjg+}F3v%?J6 zZnF*>)eP_2Y_taL`%JK4&3HG*3_bq&h}JT~*B?eSt2K_x2r%lTRIPFRKM}Zwdb^xY z+RORKp3|Sbo&Bll@UQK3#o`?v=;CKIU7>93j6t5xSUDw+75JWiiKVyXYiIcHtp9i_ zmP)78B!R9NJ|)c(Fa9E(5-T&m!X^h2Ugon>VsfjBH@MB-Ch~;pwzniGE;0Fbt7tMZ> zWjOy*_yr|s(+x<8RrQ zBPRZ_?I!x0{3iGKCU^O|sPj5vk2eL`8|YiM>-?fn*HQ7@<3fKTox6El$g3G%#w$5D z*RP%nEl$`e!>e1L*}$-LIXzkKZZym$vTLcU7^61HTq8sKF3qQiid9hI^KwhKaGX;4 zFq5GA3{khHE@7wE$Y51gB9xR#)l530Y1ECd_thkUA0zoSl~GDBwud{f3)k{K{}&dt BGavu} literal 0 HcmV?d00001 diff --git a/__pycache__/data.cpython-38.pyc b/__pycache__/data.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..82c5772992f19063e8d47b9422f8399405315a29 GIT binary patch literal 2169 zcmbVNO>^5s7?x~FvEzKWNk5W?HlcwMw{@Xk6iV8-ZKg1UB&DGPv*RJN)-H-_S!-5u zTzk?}>6yO(!>PXj&hQ5~QAQUIaM6?-ABSAvSw)>DaRLnTtmfJGdER%|`|kVd?%-g* zhUe06-+lb`kf!~tCflD$Oez?`nyzU~W4fm`bfW7T%dqTc8p$w&napB+Ea#Xk&-z(` z4X{DrA=nij1}?&W0GbitQP>Z%L+o&ZkFYV=$5Z=J;0fS7G-J@bkYc4j23&;wIPheO z4**XAznJPz08gj!UjkNZy^KAaOf|0{{!F6jXC?Ta0zM6migPB_tN3MLwTH9teHB>6 zSNOFApJV5NFQoR1hH-O&+o`(GjV!j1zq<9wibc(M!rZYjZ>>8WH zc^a&;qLr@4DhDM!vR2xhhk>o8&z=l`g>e%j7(iMa?SU2|H7X@49S_Y1`iAy}zM+4K zM5RoUqJ0>ot%oTfn(`UglTqso_AoN>wOHPx zK9e24j-Ub}o z#Bf>->TKoy`?*p^s`N(|Z8o{jN*Pk1o_AXc*0RGOG6Qv89&0iW(dMa}SE_ddE`#bk zUFXsl_F8qG2lY@it8lr;>tU7Ake+RJq7hqi8uC>&UrnL}hPq#8)XKV%DeC?De;65A zfIc#79<}QvFS#93-|={S0cK(bI1W#$z>(nyj}fB@UCb1jt+@`d-l5X1iO6cUWD|#K zF1lWwBAyg&KQ2Qj&BVLrwRn79`B@Fl+*X5FH$=-1JIL{;Eh>3DqsZKXFK|*ah^H~_ z=2f^(xlM8UAGF>3-NJ3@`Zg~&g(u?6iN}iX+I4sk<2_gSk=b5zL*5-&aDB#Qxz^&o zh_bjw-M$4kEZ1om2k?`sBI98d!CJs(>omT#6|U}vxE?`d35lcN#Jaqav&cXx zo0P5W1CES!v?o+t?R@BsbeYm+|;DTm&tc#cLp&J2s&IkKZrG F)ZbDqCE5T0 literal 0 HcmV?d00001 diff --git a/__pycache__/decision_tree.cpython-38.pyc b/__pycache__/decision_tree.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..281b85f5dd1214adf2d56269daa48d8826ebd5ce GIT binary patch literal 4825 zcmbV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#EBtz0(R|B#->7>)qV@LndEFZ-;ZDcOGPY%^EsXn(KJ z#x^MLP#Fs&3;Py^HkxU5m=*`d`e~`AHk=)g22*8&bc(B4KPv{(Mk7@Ut&-CE4p(Z9 z^;B3>jGNXsNJ{&7EFBPp1SlY;BLXUkCS~argwIU>f}j5$>^|$iF-n{MOJu9_BH8c1 zRAy2Zv;LpD7^_LyA5wWA&G6_#qk}FPw4LF zjcg+Aq;eAtEE7A!Vvea`-Z=`|l?=ME?@nj^y(}&DCWh)Qgc$VCWYc+SxQ&(#DQc?d zkr+}pgOhemqjn^2k{sB`rb}}qBBVqlBusq0L&_b)t$K$4#BL!m=}kC#klva9t^XXL zj`k-^zrXI^`jY?td->$Q$_KaqMV&9*&ctf5|HX3tvVW0}`+ov`#ZYoudwB)tTROvX z1g+t&J*Z#GC6(#bC5b2wmh|OR)y7#H4rViz%b2@r*kG?1X!&(fIs+-i;z7iiXVwrH zY{TtE{~b;?>PlUUzNQ)~*y0c7Hyo6#becKEYujR{@Xn3Syb2aa;azUV8ul literal 0 HcmV?d00001 diff --git a/__pycache__/functions.cpython-38.pyc b/__pycache__/functions.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e39b7f480b6125339589101927430b7a987dfa41 GIT binary patch literal 2998 zcmZ`*&2Jk;6rY*>@Or&=LxpGy2!SXSMhH+GV9DnUPvzw$r zYcAo8Dh{08Tgw3<{sk`l1wG6OiBr#T>WSZ*brL5LYt77?H}Ci6&71e0XSH4r8NN6F z`QzJ*Pcrs5P3Av=$p>iJCOXL^AF@_C@)pNj48_Q4Ih=UT&>eX#&(iMDA5~fv(4O>v zV68w_WPq_Mt1`qG%9@NY)?{5aFh=r>T)<$c!b^9Qj?otS><^z>1Lq454$SK zL4;DbcjNW6t!0M{Jop?C9@=%ZY>F;teLfZU*dqJp?nD%#?||bDgua-2Q~w_0Y%82` zE8r3xK%xrzX2GW6p#*Vj;I4ri9pl!)&B1LH{2rg_Bk41wFJCCQq; zFMj^jl5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 z;(u?M#HP=BY13Et2aDe;SeHB$I| zg|Bh{M7w&TuZiX%Ef^O{f)c7_RSc!U3YIZq%K))>$i945aAMjC+ttFMguwH0t9PY$ z1?+N&RhC=e!axwCtlj!iNEnMYdnI%6Bj>DF&FQg0^4Pqg463=twXdXc;;3V$@b2N! zQ2j7V?Xis)BuUg!$Zo!Ac+>FE@Vya67A>1uOD8i6n2nu$h&@tz!I+Su3c#w|2WX3E zr@8(Z_7g8Fr5e3~7MKc7nXv&YIN%Y01LPk;)RKBN1Br5`1oXc#CUeKWz_*c{62Kfo zsS5XSOyO;zWaT+1+G6^r+%05p1IbIEehWLL)M!*5jhb?z_2$3gHna`0d(BMxeE%|`w0CSp<3;|?yb@sJ5C8Bw}$_qOvKK!0P5QS zOy42#0g1a1#!YmylhwSs*Xg%+BCRP9#!n7oi~pXEUKpnxe68=%qW>^|Cfx0&(Kv{Y zFe4?mjC;g+`(7f96iOS=D(pTqk6*Ggs?cXK%Rl@y#dE7RUH8&{lEg3T^P!G{EPAej zEOwCOh*4+8w8G{Pe31*(l68(o;XJb625=< OxBJU0`6YkZpZgbk!0#9U literal 0 HcmV?d00001 diff --git a/__pycache__/product.cpython-38.pyc b/__pycache__/product.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..61b31f2bfaf6fc71e78505c5e14745004a8cb8de GIT binary patch literal 475 zcmY*U!AiqG5S`s5HWmva9{qtH><5TQp#^V6kX}M?3E7p_rcK;U1xs%BXL|A@`~t7J z`U&1V`6jVYC%iX1o0+$7roCR55WCNhhj-*JE)K&(F$CNh=$15Tu?5~_L|Wcc-%D}- zFC?lV;LbsYBB3dgT4=eY$kQHX{JL{zbG=T>G(gWj_{_s2z+HeUQIVobf<@(lW#xlC zO%M?i=mcq=<+cvoEGbOwFB9i#-_19sA0V6T(XycBC9KcHZ|ul+kbW*lSMk&t>*8_p zV(cnUXYts$MVS{d{5_dP85gb3LGfCLO3hdEQYlt*A&A6L^KDN5)*0+u*cUV-HgvCNt;A<~#RAXc`5)d9!;L)p}mzG(76FYjS_pboFwCvJG^8=zm% CL1Wth literal 0 HcmV?d00001 diff --git a/__pycache__/settings.cpython-38.pyc b/__pycache__/settings.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..19a5bce1bfd962c41ae310e0232e76f0e9f0a643 GIT binary patch literal 585 zcmY*VO;5r=5S?u+Rs<3af1(#|UW_3mka#h~gm7sZC)izRp|rSLR17!yGyV?$MX#PX zbMvCJ{V+J2_jcayyiRw<&1M}at`46McMRZ5i{mg!^a$#b=oUC|wj;b7E^uQ6j_K3+ zzc5Jk2&zpaz-1giGE0eQ`T^3WUf-SmwKrBmDsM1(7BWu! zz#9m)NRyR!FO#`gq@F6L(OGRW8!?Q-6j4t?wTOV#%GF{m_I6Rtu2WSG^+XZl$xmletKTEFA+v9a7G3Q+5a1V` C$AsGe literal 0 HcmV?d00001 diff --git a/__pycache__/shelf.cpython-38.pyc b/__pycache__/shelf.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..16977edb6d52515d580b8de86f1d43743dbf7352 GIT binary patch literal 600 zcmZWm%}T>S5T4!q7^{_@#TN)dZ(c;C(1N!jgkC~$3E8!OX&ZM_rKLCfAbRXGc=RoD z_2k)`Cug>l795ywb}~EPd^_pY>oq{T`uTkL!1zVUp*fhe(9Jo51j%xU;SMC1&Kjii z%3~&31flzlb?9bZ?1$Y}`E}7(Oh#l!j7o#gZWbi958mRm+qn4e~nY@i| z8VD=40s(zMM5+ijtQ+!*4`me;dM4*tX)t#U5@{FjZ$KYm_`PgjCq1LINjmAX($iTs zNIJ@l%UO}!>)A++%f!(5X0fOOA%@doDTGgBi3XU@mSLaDSp z!4H8O{0{yD2VXdF@|{yp%q&H!REHy$Jn?+~{CQ^N$!@nBG8~&fzP;JN)lYKH4+ov+ zI8`4FFyI->`5xyC9B@CfJqNs3EbIvrSqr3U`81@}>B$)ZEJ zO+Q5Zl7&xr+k#(i(C;4_Bvm{aWx_nhXRLjd$62Pm zQIUc6N~9Pd+#RMP9h9{!Gl6GiaWpXxXu}(3wJ?up8RP=eI@f`ETgOtE4Ft_SGEZpR zKRQS&pyr8Y1kQjq7@5ylwW0}6jb}}pIroT9v?`X^^x{)KP?Q{^ArI z<+1K1QpAS5XWaXAH-r2#3%3;klwtANTCI9MJT<5;1aSc#-vT$-6}1)*_ZJ-y!Qe2 z>Lc{#$(htbo$&w7&SqwIXJ`F>574f6Uyob#-xM61hrtkK&Jp(@L9z|%gC`*Q6k;#O z{eQ+W8lubvLP5eLBwRAdH;{PJ!y4a((|4t;$wN#z7_F&xgff?imbDQy0{{R3 literal 0 HcmV?d00001 diff --git a/main.py b/main.py index f71fa65..8cc46c1 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ from agent import Agent from settings import Settings from board import create_board, draw_board from random import randint, choice - +from mcda import choseProducts # Inicjalizacja programu i utworzenie obiektu ekrany def run(): @@ -21,6 +21,8 @@ def run(): board = create_board(screen) my_tree = decision_tree.build_tree(data.learning_data) + produsctsFromSupply = choseProducts(5) + # for row in board: # for field in row: # print(field.cost_of_travel) diff --git a/mcda.py b/mcda.py new file mode 100644 index 0000000..742828c --- /dev/null +++ b/mcda.py @@ -0,0 +1,100 @@ +from supply import * + +allProducts = create_data_products() + +color = {'black': 16, 'gold': 10, 'purple': 5, 'brown': 7, 'blue': 12, 'white': 14, 'red': 13, 'orange': 11} +shape = {'rectangle': 15, 'pack': 19, 'square': 9, 'jar': 7} +size = {'small': 7, 'medium': 16, 'big': 13} + +def sizeValue(X): + if X.size == 'small': + return X.mass/5 + if X.size == 'medium': + return X.mass/10 + if X.size == 'big': + return X.mass/20 +parameters = { + 'color': {'weights': 3, 'q': 1, 'p': 5}, + 'shape': {'weights': 4, 'q': 1, 'p': 6}, + 'mass': {'weights': 0.5, 'q': 2, 'p': 10}, + 'size': {'weights': 1, 'q': 1, 'p': 8} + +} +def getConcordance(gA, gB, q, p): + if gB <= gA + q: + return 1 + if gB <= gA + p: + return (p - gB + gA) / (p - q) + return 0 + +def getAllTypeConcordance(A, B): + concordance = 0.0 + weight_sum = 0 + + parameter = parameters['color'] + w, q, p = parameter['weights'], parameter['q'], parameter['p'] + concordance += getConcordance(color[A.color], color[B.color], q, p) * w + weight_sum += w + + parameter = parameters['shape'] + w, q, p = parameter['weights'], parameter['q'], parameter['p'] + concordance += getConcordance(shape[A.shape], shape[B.shape], q, p) * w + weight_sum += w + + parameter = parameters['mass'] + w, q, p = parameter['weights'], parameter['q'], parameter['p'] + concordance += getConcordance(sizeValue(A), sizeValue(B), q, p) * w + weight_sum += w + + parameter = parameters['size'] + w, q, p = parameter['weights'], parameter['q'], parameter['p'] + concordance += getConcordance(size[A.size], size[B.size], q, p) * w + weight_sum += w + + concordance /= weight_sum + return concordance + +def getConcordanceAllProducts(): + + C = [] + + for i in range(len(allProducts)): + c = 0 + for j in range(len(allProducts)): + if j==i: + continue + else: + c += getAllTypeConcordance(allProducts[i], allProducts[j]) + c /= len(allProducts)-1 + C.append(c) + return C + +def choseProducts(number): + C = getConcordanceAllProducts() + products = [] + prev = -1 + if number > len(allProducts): + return allProducts + while number > 0: + max = -1 + if prev == -1: + max = 0 + for j in range(len(allProducts)): + if prev == -1: + if C[max]C[j]: + max = j + elif C[max] < C[j] and C[j] < C[prev]: + max = j + prev = max + for j in range(len(allProducts)): + if C[max] == C[j]: + products.append(allProducts[j]) + print(C[j]) + number -= 1 + if number == 0: + break + print(C) + return products \ No newline at end of file diff --git a/product.py b/product.py new file mode 100644 index 0000000..e2acbe5 --- /dev/null +++ b/product.py @@ -0,0 +1,7 @@ +class Product: + + def __init__(self, color, shape, mass, size): + self.color = color + self.shape = shape + self.mass = mass + self.size = size \ No newline at end of file diff --git a/supply.py b/supply.py new file mode 100644 index 0000000..673b31a --- /dev/null +++ b/supply.py @@ -0,0 +1,64 @@ +from product import Product + + +def create_data_products(): + allProducts = [] + + product = Product('black', 'rectangle', 51, 'small') + allProducts.append(product) + product = Product('black', 'rectangle', 51, 'small') + allProducts.append(product) + product = Product('gold', 'pack', 100, 'big') + allProducts.append(product) + product = Product('purple', 'rectangle', 100, 'big') + allProducts.append(product) + product = Product('brown', 'pack', 45, 'small') + allProducts.append(product) + product = Product('blue', 'rectangle', 50, 'medium') + allProducts.append(product) + product = Product('blue', 'square', 40, 'small') + allProducts.append(product) + product = Product('blue', 'rectangle', 35, 'small') + allProducts.append(product) + product = Product('gold', 'rectangle', 40, 'medium') + allProducts.append(product) + product = Product('gold', 'rectangle', 50, 'medium') + allProducts.append(product) + product = Product('brown', 'rectangle', 55, 'medium') + allProducts.append(product) + product = Product('brown', 'rectangle', 45, 'medium') + allProducts.append(product) + product = Product('white', 'rectangle', 40, 'medium') + allProducts.append(product) + product = Product('red', 'rectangle', 50, 'medium') + allProducts.append(product) + product = Product('blue', 'rectangle', 115, 'big') + allProducts.append(product) + product = Product('white', 'rectangle', 15, 'small') + allProducts.append(product) + product = Product('red', 'pack', 70, 'medium') + allProducts.append(product) + product = Product('orange', 'rectangle', 45, 'medium') + allProducts.append(product) + product = Product('blue', 'rectangle', 55, 'medium') + allProducts.append(product) + product = Product('gold', 'rectangle', 120, 'big') + allProducts.append(product) + product = Product('white', 'rectangle', 120, 'big') + allProducts.append(product) + product = Product('white', 'jar', 600, 'big') + allProducts.append(product) + product = Product('white', 'rectangle', 25, 'small') + allProducts.append(product) + product = Product('brown', 'jar', 500, 'big') + allProducts.append(product) + product = Product('brown', 'jar', 470, 'big') + allProducts.append(product) + product = Product('red', 'jar', 250, 'medium') + allProducts.append(product) + product = Product('black', 'jar', 250, 'medium') + allProducts.append(product) + product = Product('orange', 'jar', 250, 'medium') + allProducts.append(product) + + return allProducts \ No newline at end of file From 12cfca95bc9cd8606d28dec58baa5ccbeb753eb3 Mon Sep 17 00:00:00 2001 From: Tomek Date: Tue, 19 May 2020 19:42:55 +0200 Subject: [PATCH 04/10] Dodanie raportu do podprojektu --- Raport_444420.md | 159 ++++++++++++++++++++++++++++++ __pycache__/mcda.cpython-38.pyc | Bin 2384 -> 2384 bytes __pycache__/supply.cpython-38.pyc | Bin 1288 -> 1288 bytes mcda.py | 1 - 4 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 Raport_444420.md diff --git a/Raport_444420.md b/Raport_444420.md new file mode 100644 index 0000000..01c7b80 --- /dev/null +++ b/Raport_444420.md @@ -0,0 +1,159 @@ +# Tomasz Kuczyński Raport - mcda + +### Opis podprojektu +Podprojekt ma za zadanie wybrać określoną liczbę najlepszych produktów z dostawy. +Wykorzystuj on zmodyfikowaną motodę MCDA - Multiple Criteria Decision Analysis. + +#### Uczenie modelu +Zbiór uczenia składa się z zdefiniowania wartości atrybutów: + +```javascript +color = {'black': 16, 'gold': 10, 'purple': 5, 'brown': 7, 'blue': 12, 'white': 14, 'red': 13, 'orange': 11} +shape = {'rectangle': 15, 'pack': 19, 'square': 9, 'jar': 7} +size = {'small': 7, 'medium': 16, 'big': 13} +``` +oraz ich wyliczenia: +```javascript +def sizeValue(X): + if X.size == 'small': + return X.mass/5 + if X.size == 'medium': + return X.mass/10 + if X.size == 'big': + return X.mass/20 +``` + +Składa się róznierz z parametrów: +`weights` - waga danego parametru +`q` - współczynik pomyłki (granicy błędu) pomiędzy atrybutami +`p` - maksymalna dopuszczalna różnica pomiędy atrybutami + +```javascript +parameters = { + 'color': {'weights': 3, 'q': 1, 'p': 5}, + 'shape': {'weights': 4, 'q': 1, 'p': 6}, + 'mass': {'weights': 0.5, 'q': 2, 'p': 10}, + 'size': {'weights': 1, 'q': 1, 'p': 8} +} +``` + +#### Opis kodu w wspólnym projekcie +W wspólnym projekcie w pliku main.py wywołuje funkcję wybierania 5 produktów z dostawy: + +```javascript +produsctsFromSupply = choseProducts(5) +``` + +próbna dostawa jest zapisana w pliku supply.py: + +```javascript +def create_data_products(): + allProducts = [] + + product = Product('black', 'rectangle', 51, 'small') + allProducts.append(product) + product = Product('black', 'rectangle', 51, 'small') + allProducts.append(product) + product = Product('gold', 'pack', 100, 'big') + allProducts.append(product) + ... + return allProducts + +``` + +Cały algorytm selekcji produktów znajduje się w pliku mcda.py. + +Funkcja `getConcordance(gA, gB, q, p):` ma za zadanie wyliczyć `Concordance` czyli jakość produktu A względem produktu B, za pomocą wartości atrybutów A, B odpowiednio gA, gB oraz parametrów tego atrybutu q, p i zwrócić liczbę z zakresu [0,1]. + +```javascript +def getConcordance(gA, gB, q, p): + if gB <= gA + q: + return 1 + if gB <= gA + p: + return (p - gB + gA) / (p - q) + return 0 +``` + +Funkcja `getAllTypeConcordance(A, B)` ma za zadanie wyliczyć wszystkie typy `Concordance` oraz wyliczyć ich średnią ważoną: + +```javascript +def getAllTypeConcordance(A, B): + concordance = 0.0 + weight_sum = 0 + + parameter = parameters['color'] + w, q, p = parameter['weights'], parameter['q'], parameter['p'] + concordance += getConcordance(color[A.color], color[B.color], q, p) * w + weight_sum += w + + parameter = parameters['shape'] + w, q, p = parameter['weights'], parameter['q'], parameter['p'] + concordance += getConcordance(shape[A.shape], shape[B.shape], q, p) * w + weight_sum += w + ... + concordance /= weight_sum + return concordance +``` + +Funkcja `getConcordanceAllProducts()` ma za zadanie przy pomocy funkcji `getAllTypeConcordance(A, B)` wyliczyć `Concordance` dla wszystkich produktów i zwrócić wynik w postaci listy: + +```javascript +def getConcordanceAllProducts(): + C = [] + + for i in range(len(allProducts)): + c = 0 + for j in range(len(allProducts)): + if j==i: + continue + else: + c += getAllTypeConcordance(allProducts[i], allProducts[j]) + c /= len(allProducts)-1 + C.append(c) + return C +``` + +Funkcja `choseProducts(number)` ma za zadanie wybrać `number` produktów z dostawy na podstawie listy `Concordance` zwróconej przez funkcję `getConcordanceAllProducts()`. + +```javascript +def choseProducts(number): + C = getConcordanceAllProducts() + products = [] + prev = -1 + if number > len(allProducts): + return allProducts + while number > 0: + max = -1 + if prev == -1: + max = 0 + for j in range(len(allProducts)): + if prev == -1: + if C[max]C[j]: + max = j + elif C[max] < C[j] and C[j] < C[prev]: + max = j + prev = max + for j in range(len(allProducts)): + if C[max] == C[j]: + products.append(allProducts[j]) + print(C[j]) + number -= 1 + if number == 0: + break + print(C) + return products +``` + +`print(C[j])` oraz `print(C)` służy do sprawdzenia poprawności algorytmu. + +### Uruchomienie algorytmu i jego działanie +Film przedstawiający uruchomienie aplikacji: +https://www.youtube.com/watch?v=DmwDlJkjtjs +Parametry pojawiające się w terminalu: +1.Concordance `number` najlepszych produktów (`print(C[j])`). +2.Lista wszystkich Concordance ( `print(C)`). + + diff --git a/__pycache__/mcda.cpython-38.pyc b/__pycache__/mcda.cpython-38.pyc index 4a133b5fdd1c590041e86e23dc4b463c829f22fa..79e10a93b034ae505ce236949eb877dffbb5834c 100644 GIT binary patch delta 37 rcmca0bU}zWl$V!_0SLJHkHqzFfquI<>lpK0D|MfM>cZ*WdQ&y$OQxd delta 20 acmeC+>fquI<>lpK00O)Fhc|NnWdQ&z%mqdO diff --git a/mcda.py b/mcda.py index 742828c..68dd463 100644 --- a/mcda.py +++ b/mcda.py @@ -55,7 +55,6 @@ def getAllTypeConcordance(A, B): return concordance def getConcordanceAllProducts(): - C = [] for i in range(len(allProducts)): From e28c1268233dde25cafc388b94118515654c8646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kuczy=C5=84ski?= Date: Tue, 19 May 2020 17:47:00 +0000 Subject: [PATCH 05/10] poprawa wizualna Raportu --- Raport_444420.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Raport_444420.md b/Raport_444420.md index 01c7b80..45706d9 100644 --- a/Raport_444420.md +++ b/Raport_444420.md @@ -24,8 +24,11 @@ def sizeValue(X): ``` Składa się róznierz z parametrów: + `weights` - waga danego parametru + `q` - współczynik pomyłki (granicy błędu) pomiędzy atrybutami + `p` - maksymalna dopuszczalna różnica pomiędy atrybutami ```javascript @@ -152,8 +155,11 @@ def choseProducts(number): ### Uruchomienie algorytmu i jego działanie Film przedstawiający uruchomienie aplikacji: https://www.youtube.com/watch?v=DmwDlJkjtjs + Parametry pojawiające się w terminalu: + 1.Concordance `number` najlepszych produktów (`print(C[j])`). + 2.Lista wszystkich Concordance ( `print(C)`). From abf5829c3426e92ea4c08c6d8cc56a75dee54228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20=C5=81ukasik?= Date: Tue, 19 May 2020 22:21:13 +0200 Subject: [PATCH 06/10] zmiany --- __pycache__/data.cpython-37.pyc | Bin 2311 -> 2311 bytes __pycache__/field.cpython-37.pyc | Bin 1606 -> 1606 bytes data.py | 2 +- field.py | 5 ++--- main.py | 1 - 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/__pycache__/data.cpython-37.pyc b/__pycache__/data.cpython-37.pyc index 77ec7fdb49dbcfe2511f82a7ea2417da6b3f140e..196eabc65826b54364b04b6b53e72da128d0325d 100644 GIT binary patch delta 22 ccmZn{Y8T>l;^pOH0D_JahvRl^l;^pOH0D|`i565la$oq=}06ysk?f?J) diff --git a/__pycache__/field.cpython-37.pyc b/__pycache__/field.cpython-37.pyc index 2a25f2452f0d68a928b0434daf9e793fe34b7a0b..a6aa6db7e4a8e075da7cb20f8641036987226605 100644 GIT binary patch delta 47 zcmX@cbBu@AiIE)e8V7 Cat$~D diff --git a/data.py b/data.py index 4c3a444..b8e059f 100644 --- a/data.py +++ b/data.py @@ -40,7 +40,7 @@ learning_data = [ ['gold', 'rectangle', 40, 'medium', 'Twix'], ['gold', 'rectangle', 50, 'medium', 'Prince-polo'], ['brown', 'rectangle', 55, 'medium', 'Snickers'], - ['brown', 'rectangle', 45, 'medium', 'Lion'], + ['brown', 'rectangle', 45, 'medium', 'Lion'], ['white', 'rectangle', 40, 'medium', 'Kinder-bueno'], ['red', 'rectangle', 50, 'medium', 'Kit-kat'], ['blue', 'rectangle', 115, 'big', 'Wedel'], diff --git a/field.py b/field.py index d90ffa6..89f246a 100644 --- a/field.py +++ b/field.py @@ -33,7 +33,6 @@ class Field: self.rect.center = (center_x, center_y) - # Metoda do wyświetlania pola na ekranie def blitme(self): self.screen.blit(self.image, self.rect) @@ -49,5 +48,5 @@ class Field: self.neighbors.append(board[self.y + 1][self.x]) def addShelf(self): - shelf = Shelf(len(self.shelves)+1) - self.shelves.append(shelf) \ No newline at end of file + shelf = Shelf(len(self.shelves) + 1) + self.shelves.append(shelf) diff --git a/main.py b/main.py index f71fa65..0f4925b 100644 --- a/main.py +++ b/main.py @@ -46,7 +46,6 @@ def run(): elif event.key == pygame.K_SPACE: board[9][0].item = choice(data.learning_data) print("Wybrano: " + board[9][0].item[-1]) - board[9][0].item[-1] = 'Something' field = board[9][0] if not field.is_shelf: path = functions.a_star(board[agent.y][agent.x], field, board) From d55884cce61e80b2978d7e6e45a4da75c8feeb55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20=C5=81ukasik?= Date: Tue, 19 May 2020 23:27:29 +0200 Subject: [PATCH 07/10] stworzenie raportu --- .idea/misc.xml | 2 +- .idea/wozek.iml | 2 +- {Archiwum => Raporty}/README.md | 0 Raport_444420.md => Raporty/Raport_444420.md | 0 {Archiwum => Raporty}/environment.md | 0 Raporty/raport_444428.md | 132 ++++++++++++++++++ .../route-planning.md | 0 __pycache__/mcda.cpython-37.pyc | Bin 0 -> 2370 bytes __pycache__/product.cpython-37.pyc | Bin 0 -> 455 bytes __pycache__/supply.cpython-37.pyc | Bin 0 -> 1272 bytes 10 files changed, 134 insertions(+), 2 deletions(-) rename {Archiwum => Raporty}/README.md (100%) rename Raport_444420.md => Raporty/Raport_444420.md (100%) rename {Archiwum => Raporty}/environment.md (100%) create mode 100644 Raporty/raport_444428.md rename route-planning.md => Raporty/route-planning.md (100%) create mode 100644 __pycache__/mcda.cpython-37.pyc create mode 100644 __pycache__/product.cpython-37.pyc create mode 100644 __pycache__/supply.cpython-37.pyc diff --git a/.idea/misc.xml b/.idea/misc.xml index adaa126..715ed69 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/.idea/wozek.iml b/.idea/wozek.iml index 904114b..a9742fc 100644 --- a/.idea/wozek.iml +++ b/.idea/wozek.iml @@ -4,7 +4,7 @@ - + diff --git a/Archiwum/README.md b/Raporty/README.md similarity index 100% rename from Archiwum/README.md rename to Raporty/README.md diff --git a/Raport_444420.md b/Raporty/Raport_444420.md similarity index 100% rename from Raport_444420.md rename to Raporty/Raport_444420.md diff --git a/Archiwum/environment.md b/Raporty/environment.md similarity index 100% rename from Archiwum/environment.md rename to Raporty/environment.md diff --git a/Raporty/raport_444428.md b/Raporty/raport_444428.md new file mode 100644 index 0000000..f99651d --- /dev/null +++ b/Raporty/raport_444428.md @@ -0,0 +1,132 @@ +# Wojciech Lukasik - drzewa decyzyjne, algorytm CART + +### Opis podprojektu +Podprojekt implementuje tworzenie drzewa decyzyjnego w oparciu o algorytm CART +(Classification And Regression Tree), które pomaga Agentowi w rozpoznaniu słodyczy na podstawie +ich cech fizycznych (kolor, kształt, masa, rozmiar). + +Wszystkie funkcje oraz klasy wykorzystywane w tym podprojekcie znajdują się w pliku decision_tree.py, +dane uczące znajdują się w pliku data.py w liście learning_data + +### Tworzenie drzewa decyzyjnego + +Główną funkcją jest build_tree(rows), która jak wskazuje nazwa tworzy drzewo. Funkcja przyjmuje +jako argument listę zawierającą zestaw danych, w tym przypadku będą to słodycze o różnych właściwościach. + +```python +def build_tree(rows): + gain, question = find_best_split(rows) + + if gain == 0: + return Leaf(rows) + + true_rows, false_rows = partition(rows, question) + + true_branch = build_tree(true_rows) + + false_branch = build_tree(false_rows) + + return DecisionNode(question, true_branch, false_branch) +``` + +Drzewo jest budowane w oparciu o najlepsze możlwe podziały (najbardziej korzystne 'pytanie', które można zadać). +Zajmuje się tym funkcja + +`find_best_split(rows)` która dla wszystkich właściwości przekazanego zestawu informacji +wylicza dla nich 'zysk informacji'. + +Jeżeli nie otrzymujemy żadnych informacji (gain == 0) to znaczy, że znajdujemy +się w liściu drzewa. + +```python +def find_best_split(rows): + """ znajdź najlepsze możliwe pytanie do zadania, sprawdzając wszystkie + właściwośći oraz licząc dla nich 'info_gain' """ + best_gain = 0 + best_question = None + current_uncertainty = gini(rows) + n_features = len(rows[0]) - 1 + + for col in range(n_features): + values = set([row[col] for row in rows]) + + for val in values: + question = Question(col, val) + + true_rows, false_rows = partition(rows, question) + + if len(true_rows) == 0 or len(false_rows) == 0: + continue + + gain = info_gain(true_rows, false_rows, current_uncertainty) + + if gain > best_gain: + best_gain, best_question = gain, question + + return best_gain, best_question +``` + +Zysk informacji z danego podziału otrzymujemy obliczając wartość 'Gini Impurity'. Jest to miara tego jak często losowo +wybrany element zbioru byłby źle skategoryzowany, gdyby przypisać mu losową kategorię spośród wszystkich kategorii +znajdujących się w danym zbiorze. + +```python +def gini(rows): + counts = class_counts(rows) + impurity = 1 + for lbl in counts: + prob_of_lbl = counts[lbl] / float(len(rows)) + impurity -= prob_of_lbl ** 2 + return impurity +``` +`class_counts(rows)` to funkcja, która dla danego zestawu danych zwraca wszystkie unikalne klasy oraz liczbę ich wystąpień. + +Dla przykładu, dla zestawu w którym wszystkie elementy podchodzą pod tę samą kategorię wartość Gini będzie równa zero, +natomiast dla zbioru w którym znajdują się dwie kategorie wartość ta wyniesie 0,5. + +Po znalezieniu najbardziej optymalnego pytania, algorytm dzieli zestaw na elementy, dla których pytanie jest prawdziwe +(true_rows), oraz te dla których jest fałszywe (false_rows). Następnie wykonuje rekurencyjnie procedurę build_tree dla +obu poddrzew tak długo aż nie dojdzie do liści. + +Element o zadanym zestawie cech, zostaje odnaleziony w drzewie dzięki prostej procedurze + +`classify(row, node)` 'row' to lista cech elementu, natomiast 'node' na początu jest korzeniem już zbudowanego drzewa. + +Element jest odnaleziony dzięki +rekurencyjnym porównaniom atrybutów elementu z pytaniami w kolejnych węzłach drzewa. + +```python +def classify(row, node): + if isinstance(node, Leaf): + return node.predicions + + if node.question.match(row): + return classify(row, node.true_branch) + else: + return classify(row, node.false_branch) +``` + +### Zestaw uczący + +Zestaw budujący drzewo to lista zawierająca 27 przykładowych słodyczy. Ich atrybuty zapisane są w formacie ['kolor', +'kształt', 'masa', 'wielkość', 'nazwa']. Oczywiście przy wyszukiwaniu elementu w drzewie jego nazwa nie jest potrzebna +ponieważ to jej szukamy. Przykładowe elementy z zestawu uczącego: + +```python + ['black', 'rectangle', 51, 'small', 'Mars'], + ['gold', 'pack', 100, 'big', 'Haribo'], + ['purple', 'rectangle', 100, 'big', 'Milka'], + ['brown', 'pack', 45, 'small', 'M&M'], +``` + +### Implementacja w projekcie + +Przy rozpoczęciu głównej pętli programu w pliku `main.py` drzewo `my_tree` zostaje zbudowane w oparciu o dane +`data.learning_data`. + +Gdy program już działa, po wciśnięciu `spacji` jeden ze słodyczy zostanie losowo wybrany z zestawu `data.learning_data` +oraz umieszczony na polu `board[9][0]`, a jego nazwa zostanie wypisana w konsoli. Następnie Agent przemieszcza się do +punktu `board[9][0]` i rozpoczne procedurę wyszukiwania elementu w zbudowanym drzewie. Na końcu wypisze w +konsoli nazwę produktu. + + diff --git a/route-planning.md b/Raporty/route-planning.md similarity index 100% rename from route-planning.md rename to Raporty/route-planning.md diff --git a/__pycache__/mcda.cpython-37.pyc b/__pycache__/mcda.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a51297a23ec784757ab4f8f2d3f374ac4308af95 GIT binary patch literal 2370 zcma)7&u<(x6t+E{+1bsHhBR%OrcKiXN*1Xls-P`Zp-o$f98grL6+xpwH5rdKo6PRc zdS*$AW=_k28yq?0P>x9a4@eb%g-=MFmcIaTf$w?q6H%!i`PqK9pZ&h~JPeLuq3A2c{DRdgPpWB}^Vm2##)6Ix+l_c|hAf;VLDe&F@?=C zC4*kp?S&fKwnJTajGMK>Br#qqR?S|^IGfEz#IcnMwF31KYW4u4VA}wBN9ZZ^xDvDM z=}_lDw`6tlNasR#&+0tVDb#vpO<#l^P0s6C5|YFvh`|&@T^N})zrkHwVU`hOU;NDU zRm}Xo@c8b=)4Zpe;l>l)*@joy#>!{cZ!X_l-e^TCypg^zRoeS`2yn>zjDTglcJ%2* zj0X-0at+>BcH?GaE6)t?8lDd5G6N5yfr|3`{Q>zu@F9Su8+DS724q`d8tW@i>N$vr zwo##$tXsT3K&RjZE5tP0;d(-GU`1ocj+YCk;1_`2G&F^{z$``r7&&YD9qiR~MeBN9 z2BNWo`cS`1x~0PjJF6EkG~8a;BUaR?0#uIl~}bE4>+bCRpi~URfzb&U1m#iW!EMQ(JgNr7sJ2irr?V zfJ-h~vQ~K`YYwd8+#H}#`&w)M8(EVD>+@U|yw6{2srp8iT-*x?Uatgn$cj@}I#9ucVSnOYj^uodUA&TOEx-DQ_8(pusf9tFN)_`_f% zI*xQu8&ddr)@udTBP)jQo;Z#Y=mc5Lfh;RY^6W(#pWqA~krB5T7$b$xFYyKLpK9k$ zjWtm`q777t{1sHos2rUJE7{(5&WJ00MB*{~GAKFmZ12`7?X}XOWWaNAr@Pc$0=pby zmE{(=&=F6@a-W^7BQPyGp92PxE&h#2xnyUY5_1Y3D73FkKRQ- z!NTrIz7B*Ig zHUO?HoxLZgPJV!sPwp1_uR^?(2p!I+pit6KzmGoraqfT+)-R!7Jz?Ef>#RG!ZdchA zlss~6@DIv~7 zXy9eNG)-OvQ<09tJbtdiJbZq5si6(J$2(o;Xhz623qD<4rhz#h>-Z{{`Q-?~DKd literal 0 HcmV?d00001 diff --git a/__pycache__/product.cpython-37.pyc b/__pycache__/product.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c5d2555af12938ca13d899404e7bb12fa59a4007 GIT binary patch literal 455 zcmYjMJx{|h5Is8y4HcCTVq|6LKvi`_2+D`Vf-0nLQG^x6K?J2A*y%u(jsBTV`~(($ zg;#z88x!vmih9<2ced}IpRYQdHX%MPJ|EtZzj(6=55*9$2cTQhq{Rw&lM!h-rmmOb z{68eBAz%+d8AU=0TMUkgH^!u)LZ)SRtmT7<<4$eGy4cH@4B`Q)>NwBCqu&jKr zrwIaL1dSk_6*J=k`;^Qx=T8!Aop1AH)(w!e;?c06Ve`gk;y2c0T1Y>~H>dHqT-^0hcW2yPPxd!2iH@JqUJKFSNMJdfYT#stHtSnUYU~&WAXk;?$qf8?j?nq7I#h z;C*n+r|cu2@=vJw4?Khj8ZdW;KaV;tJVt)gq2EG&8y3#!v|tgIYWU|Ic!)Yn4jsZ> z`Z40?9el!@4*Wumey2vC^1A4#59wTT#NWaCTz1^sMZPN@(s#vA`7YPo>&92$N)7+2 zBhDCB;F^O^_;m-~L44Jb7q7v)E_}-HP2boy;ZP>&ftgn#EtBy`3VR2iu?cmaNNIx6 zM1lzlq*x%_A7&#H6_qNaz_V&{IJTR#5e#J|Y@e1k^yq|F;_i!{9?1e)!!QEswm{q?c&IEQYDg7 z>_Ji{d#4II!1KC9!+78=@R8W+Rcf04SoA{k&JVRzl{bi`QX6}BD|0O9NV2zlj H>a_e{-z^;D literal 0 HcmV?d00001 From 60c2cbc17ad804a28adc72d0dc95d92a5142edfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20=C5=81ukasik?= Date: Tue, 19 May 2020 21:41:26 +0000 Subject: [PATCH 08/10] Zaktualizuj 'Raporty/raport_444428.md' --- Raporty/raport_444428.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Raporty/raport_444428.md b/Raporty/raport_444428.md index f99651d..7f9d0b9 100644 --- a/Raporty/raport_444428.md +++ b/Raporty/raport_444428.md @@ -10,8 +10,11 @@ dane uczące znajdują się w pliku data.py w liście learning_data ### Tworzenie drzewa decyzyjnego -Główną funkcją jest build_tree(rows), która jak wskazuje nazwa tworzy drzewo. Funkcja przyjmuje -jako argument listę zawierającą zestaw danych, w tym przypadku będą to słodycze o różnych właściwościach. +Główną funkcją jest + +`build_tree(rows)` która jak wskazuje nazwa tworzy drzewo. + +Funkcja przyjmuje jako argument listę zawierającą zestaw danych, w tym przypadku będą to słodycze o różnych właściwościach. ```python def build_tree(rows): @@ -79,14 +82,12 @@ def gini(rows): impurity -= prob_of_lbl ** 2 return impurity ``` -`class_counts(rows)` to funkcja, która dla danego zestawu danych zwraca wszystkie unikalne klasy oraz liczbę ich wystąpień. +`class_counts(rows)` to funkcja, która dla danego zestawu danych zwraca wszystkie unikalne 'kategorie' oraz liczbę ich wystąpień. -Dla przykładu, dla zestawu w którym wszystkie elementy podchodzą pod tę samą kategorię wartość Gini będzie równa zero, -natomiast dla zbioru w którym znajdują się dwie kategorie wartość ta wyniesie 0,5. +Dla przykładu, w zestawie w którym wszystkie elementy podchodzą pod tę samą kategorię wartość Gini Impurity będzie równa zero, natomiast w zbiorze w którym znajdują się dwie kategorie wartość ta wyniesie 0,5. Im więcej różnych kategorii tym bardziej wartość Gini Impurity będzie zbliżała się do 1. Po znalezieniu najbardziej optymalnego pytania, algorytm dzieli zestaw na elementy, dla których pytanie jest prawdziwe -(true_rows), oraz te dla których jest fałszywe (false_rows). Następnie wykonuje rekurencyjnie procedurę build_tree dla -obu poddrzew tak długo aż nie dojdzie do liści. +(true_rows), oraz te dla których jest fałszywe (false_rows). Następnie wykonuje rekurencyjnie procedurę `build_tree` dla obu poddrzew tak długo aż nie dojdzie do liści. Element o zadanym zestawie cech, zostaje odnaleziony w drzewie dzięki prostej procedurze From 2f5ffee005042f3197976a070ba58bd543744e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20=C5=81ukasik?= Date: Tue, 19 May 2020 21:42:01 +0000 Subject: [PATCH 09/10] Zaktualizuj 'Raporty/raport_444428.md' --- Raporty/raport_444428.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Raporty/raport_444428.md b/Raporty/raport_444428.md index 7f9d0b9..b968c8f 100644 --- a/Raporty/raport_444428.md +++ b/Raporty/raport_444428.md @@ -1,4 +1,4 @@ -# Wojciech Lukasik - drzewa decyzyjne, algorytm CART +# Wojciech Łukasik - drzewa decyzyjne, algorytm CART ### Opis podprojektu Podprojekt implementuje tworzenie drzewa decyzyjnego w oparciu o algorytm CART From 35ffb5bf040631e4cf993db4b89b3236f737d635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20=C5=81ukasik?= Date: Tue, 19 May 2020 22:30:11 +0000 Subject: [PATCH 10/10] Zaktualizuj 'Raporty/raport_444428.md' --- Raporty/raport_444428.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/Raporty/raport_444428.md b/Raporty/raport_444428.md index b968c8f..12c5088 100644 --- a/Raporty/raport_444428.md +++ b/Raporty/raport_444428.md @@ -43,8 +43,6 @@ się w liściu drzewa. ```python def find_best_split(rows): - """ znajdź najlepsze możliwe pytanie do zadania, sprawdzając wszystkie - właściwośći oraz licząc dla nich 'info_gain' """ best_gain = 0 best_question = None current_uncertainty = gini(rows)