-
+
+
\ 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/Archiwum/README.md b/Raporty/README.md
similarity index 100%
rename from Archiwum/README.md
rename to Raporty/README.md
diff --git a/Raporty/Raport_444420.md b/Raporty/Raport_444420.md
new file mode 100644
index 0000000..45706d9
--- /dev/null
+++ b/Raporty/Raport_444420.md
@@ -0,0 +1,165 @@
+# 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/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..12c5088
--- /dev/null
+++ b/Raporty/raport_444428.md
@@ -0,0 +1,131 @@
+# Wojciech Łukasik - 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):
+ 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 'kategorie' oraz liczbę ich wystąpień.
+
+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.
+
+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 99%
rename from route-planning.md
rename to Raporty/route-planning.md
index ca850b4..a858ead 100644
--- a/route-planning.md
+++ b/Raporty/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.
diff --git a/__pycache__/agent.cpython-38.pyc b/__pycache__/agent.cpython-38.pyc
new file mode 100644
index 0000000..7eee450
Binary files /dev/null and b/__pycache__/agent.cpython-38.pyc differ
diff --git a/__pycache__/board.cpython-38.pyc b/__pycache__/board.cpython-38.pyc
new file mode 100644
index 0000000..a0ab288
Binary files /dev/null and b/__pycache__/board.cpython-38.pyc differ
diff --git a/__pycache__/data.cpython-37.pyc b/__pycache__/data.cpython-37.pyc
new file mode 100644
index 0000000..196eabc
Binary files /dev/null and b/__pycache__/data.cpython-37.pyc differ
diff --git a/__pycache__/data.cpython-38.pyc b/__pycache__/data.cpython-38.pyc
new file mode 100644
index 0000000..82c5772
Binary files /dev/null and b/__pycache__/data.cpython-38.pyc differ
diff --git a/__pycache__/decision_tree.cpython-37.pyc b/__pycache__/decision_tree.cpython-37.pyc
new file mode 100644
index 0000000..5b41fdd
Binary files /dev/null and b/__pycache__/decision_tree.cpython-37.pyc differ
diff --git a/__pycache__/decision_tree.cpython-38.pyc b/__pycache__/decision_tree.cpython-38.pyc
new file mode 100644
index 0000000..281b85f
Binary files /dev/null and b/__pycache__/decision_tree.cpython-38.pyc differ
diff --git a/__pycache__/field.cpython-37.pyc b/__pycache__/field.cpython-37.pyc
index bd80bce..a6aa6db 100644
Binary files a/__pycache__/field.cpython-37.pyc and b/__pycache__/field.cpython-37.pyc differ
diff --git a/__pycache__/field.cpython-38.pyc b/__pycache__/field.cpython-38.pyc
new file mode 100644
index 0000000..4413c80
Binary files /dev/null and b/__pycache__/field.cpython-38.pyc differ
diff --git a/__pycache__/functions.cpython-38.pyc b/__pycache__/functions.cpython-38.pyc
new file mode 100644
index 0000000..e39b7f4
Binary files /dev/null and b/__pycache__/functions.cpython-38.pyc differ
diff --git a/__pycache__/mcda.cpython-37.pyc b/__pycache__/mcda.cpython-37.pyc
new file mode 100644
index 0000000..a51297a
Binary files /dev/null and b/__pycache__/mcda.cpython-37.pyc differ
diff --git a/__pycache__/mcda.cpython-38.pyc b/__pycache__/mcda.cpython-38.pyc
new file mode 100644
index 0000000..79e10a9
Binary files /dev/null and b/__pycache__/mcda.cpython-38.pyc differ
diff --git a/__pycache__/product.cpython-37.pyc b/__pycache__/product.cpython-37.pyc
new file mode 100644
index 0000000..c5d2555
Binary files /dev/null and b/__pycache__/product.cpython-37.pyc differ
diff --git a/__pycache__/product.cpython-38.pyc b/__pycache__/product.cpython-38.pyc
new file mode 100644
index 0000000..61b31f2
Binary files /dev/null and b/__pycache__/product.cpython-38.pyc differ
diff --git a/__pycache__/settings.cpython-38.pyc b/__pycache__/settings.cpython-38.pyc
new file mode 100644
index 0000000..19a5bce
Binary files /dev/null and b/__pycache__/settings.cpython-38.pyc differ
diff --git a/__pycache__/shelf.cpython-37.pyc b/__pycache__/shelf.cpython-37.pyc
new file mode 100644
index 0000000..12cbc7c
Binary files /dev/null and b/__pycache__/shelf.cpython-37.pyc differ
diff --git a/__pycache__/shelf.cpython-38.pyc b/__pycache__/shelf.cpython-38.pyc
new file mode 100644
index 0000000..16977ed
Binary files /dev/null and b/__pycache__/shelf.cpython-38.pyc differ
diff --git a/__pycache__/supply.cpython-37.pyc b/__pycache__/supply.cpython-37.pyc
new file mode 100644
index 0000000..fb3c123
Binary files /dev/null and b/__pycache__/supply.cpython-37.pyc differ
diff --git a/__pycache__/supply.cpython-38.pyc b/__pycache__/supply.cpython-38.pyc
new file mode 100644
index 0000000..8dba534
Binary files /dev/null and b/__pycache__/supply.cpython-38.pyc differ
diff --git a/__pycache__/sweets.cpython-37.pyc b/__pycache__/sweets.cpython-37.pyc
new file mode 100644
index 0000000..c1890e1
Binary files /dev/null and b/__pycache__/sweets.cpython-37.pyc differ
diff --git a/__pycache__/sweets.cpython-38.pyc b/__pycache__/sweets.cpython-38.pyc
new file mode 100644
index 0000000..8bdc65f
Binary files /dev/null and b/__pycache__/sweets.cpython-38.pyc differ
diff --git a/candy.py b/candy.py
new file mode 100644
index 0000000..186a58b
--- /dev/null
+++ b/candy.py
@@ -0,0 +1,9 @@
+
+
+class Candy:
+ def __init__(self, producent, type, price):
+
+ self.producent = producent
+ self.type = type
+ self.price = price
+
diff --git a/data.py b/data.py
index ac9ddb2..b8e059f 100644
--- a/data.py
+++ b/data.py
@@ -25,7 +25,39 @@ def create_data_sweets():
sweet = Sweets('Maoam', 'truskawkowy', 'guma', 'maly', 0.25)
allProducts.append(sweet)
- return allProducts
+ return allProducts
+
+
+learning_data = [
+ # kolor, kształt, waga, rozmiar, nazwa
+ ['black', 'rectangle', 51, 'small', 'Mars'],
+ ['gold', 'pack', 100, 'big', 'Haribo'],
+ ['purple', 'rectangle', 100, 'big', 'Milka'],
+ ['brown', 'pack', 45, 'small', 'M&M'],
+ ['blue', 'rectangle', 50, 'medium', 'Bounty'],
+ ['blue', 'square', 40, 'small', 'Knoppers'],
+ ['blue', 'rectangle', 35, 'small', 'Milky-way'],
+ ['gold', 'rectangle', 40, 'medium', 'Twix'],
+ ['gold', 'rectangle', 50, 'medium', 'Prince-polo'],
+ ['brown', 'rectangle', 55, 'medium', 'Snickers'],
+ ['brown', 'rectangle', 45, 'medium', 'Lion'],
+ ['white', 'rectangle', 40, 'medium', 'Kinder-bueno'],
+ ['red', 'rectangle', 50, 'medium', 'Kit-kat'],
+ ['blue', 'rectangle', 115, 'big', 'Wedel'],
+ ['white', 'rectangle', 15, 'small', 'Krowka'],
+ ['red', 'pack', 70, 'medium', 'Skittles'],
+ ['orange', 'rectangle', 45, 'medium', 'Reeses'],
+ ['blue', 'rectangle', 55, 'medium', 'Oreo'],
+ ['gold', 'rectangle', 120, 'big', 'Ferrero-rocher'],
+ ['white', 'rectangle', 120, 'big', 'Rafaello'],
+ ['white', 'jar', 600, 'big', 'Nutella'],
+ ['white', 'rectangle', 25, 'small', 'Duplo'],
+ ['brown', 'jar', 500, 'big', 'GoOn'],
+ ['brown', 'jar', 470, 'big', 'Active Orzechowe'],
+ ['red', 'jar', 250, 'medium', 'Strawberry Jam'],
+ ['black', 'jar', 250, 'medium', 'Blackberry Jam'],
+ ['orange', 'jar', 250, 'medium', 'Peach Jam'],
+]
def create_data_dict():
@@ -52,4 +84,4 @@ def create_data_dict():
sweet = Sweets('Maoam', 'truskawkowy', 'guma', 'maly', 0.25)
products_as_dict.append(vars(sweet))
- return products_as_dict
+ return products_as_dict
diff --git a/data.py.orig b/data.py.orig
new file mode 100644
index 0000000..d7b921a
--- /dev/null
+++ b/data.py.orig
@@ -0,0 +1,91 @@
+from sweets import Sweets
+
+
+def create_data_sweets():
+ allProducts = []
+
+ sweet = Sweets('Mars', 'czekoladowy', 'baton', 'sredni', 2.49)
+ allProducts.append(sweet)
+ sweet = Sweets('Mars', 'czekoladowy', 'czekolada', 'duzy', 4.99)
+ allProducts.append(sweet)
+ sweet = Sweets('Mars', 'czekoladowy', 'czekolada', 'ogromny', 11.26)
+ allProducts.append(sweet)
+ sweet = Sweets('M&M', 'czekoladowy', 'czekolada', 'duzy', 3.99)
+ allProducts.append(sweet)
+ sweet = Sweets('M&M', 'czekoladowy', 'baton', 'sredni', 2.89)
+ allProducts.append(sweet)
+ sweet = Sweets('Nestle', 'bananowy', 'landrynka', 'maly', 0.39)
+ allProducts.append(sweet)
+ sweet = Sweets('Nestle', 'truskawkowy', 'landrynka', 'maly', 0.39)
+ allProducts.append(sweet)
+ sweet = Sweets('Nestle', 'cola', 'landrynka', 'maly', 0.49)
+ allProducts.append(sweet)
+ sweet = Sweets('Wedel', 'czekoladowy', 'baton', 'sredni', 1.99)
+ allProducts.append(sweet)
+ sweet = Sweets('Maoam', 'truskawkowy', 'guma', 'maly', 0.25)
+ allProducts.append(sweet)
+
+<<<<<<< HEAD
+ return allProducts
+
+
+learning_data = [
+ # kolor, kształt, waga, rozmiar, nazwa
+ ['black', 'rectangle', 51, 'small', 'Mars'],
+ ['gold', 'pack', 100, 'big', 'Haribo'],
+ ['purple', 'rectangle', 100, 'big', 'Milka'],
+ ['brown', 'pack', 45, 'small', 'M&M'],
+ ['blue', 'rectangle', 50, 'medium', 'Bounty'],
+ ['blue', 'square', 40, 'small', 'Knoppers'],
+ ['blue', 'rectangle', 35, 'small', 'Milky-way'],
+ ['gold', 'rectangle', 40, 'medium', 'Twix'],
+ ['gold', 'rectangle', 50, 'medium', 'Prince-polo'],
+ ['brown', 'rectangle', 55, 'medium', 'Snickers'],
+ ['brown', 'rectangle', 45, 'medium', 'Lion'],
+ ['white', 'rectangle', 40, 'medium', 'Kinder-bueno'],
+ ['red', 'rectangle', 50, 'medium', 'Kit-kat'],
+ ['blue', 'rectangle', 115, 'big', 'Wedel'],
+ ['white', 'rectangle', 15, 'small', 'Krowka'],
+ ['red', 'pack', 70, 'medium', 'Skittles'],
+ ['orange', 'rectangle', 45, 'medium', 'Reeses'],
+ ['blue', 'rectangle', 55, 'medium', 'Oreo'],
+ ['gold', 'rectangle', 120, 'big', 'Ferrero-rocher'],
+ ['white', 'rectangle', 120, 'big', 'Rafaello'],
+ ['white', 'jar', 600, 'big', 'Nutella'],
+ ['white', 'rectangle', 25, 'small', 'Duplo'],
+ ['brown', 'jar', 500, 'big', 'GoOn'],
+ ['brown', 'jar', 470, 'big', 'Active Orzechowe'],
+ ['red', 'jar', 250, 'medium', 'Strawberry Jam'],
+ ['black', 'jar', 250, 'medium', 'Blackberry Jam'],
+ ['orange', 'jar', 250, 'medium', 'Peach Jam'],
+]
+=======
+ return allProducts
+
+
+def create_data_dict():
+ products_as_dict = []
+
+ sweet = Sweets('Mars', 'czekoladowy', 'baton', 'sredni', 2.49)
+ products_as_dict.append(vars(sweet))
+ sweet = Sweets('Mars', 'czekoladowy', 'czekolada', 'duzy', 4.99)
+ products_as_dict.append(vars(sweet))
+ sweet = Sweets('Mars', 'czekoladowy', 'czekolada', 'ogromny', 11.26)
+ products_as_dict.append(vars(sweet))
+ sweet = Sweets('M&M', 'czekoladowy', 'czekolada', 'duzy', 3.99)
+ products_as_dict.append(vars(sweet))
+ sweet = Sweets('M&M', 'czekoladowy', 'baton', 'sredni', 2.89)
+ products_as_dict.append(vars(sweet))
+ sweet = Sweets('Nestle', 'bananowy', 'landrynka', 'maly', 0.39)
+ products_as_dict.append(vars(sweet))
+ sweet = Sweets('Nestle', 'truskawkowy', 'landrynka', 'maly', 0.39)
+ products_as_dict.append(vars(sweet))
+ sweet = Sweets('Nestle', 'cola', 'landrynka', 'maly', 0.49)
+ products_as_dict.append(vars(sweet))
+ sweet = Sweets('Wedel', 'czekoladowy', 'baton', 'sredni', 1.99)
+ products_as_dict.append(vars(sweet))
+ sweet = Sweets('Maoam', 'truskawkowy', 'guma', 'maly', 0.25)
+ products_as_dict.append(vars(sweet))
+
+ return products_as_dict
+>>>>>>> upstream/master
diff --git a/decision_tree.py b/decision_tree.py
new file mode 100644
index 0000000..1f6c05b
--- /dev/null
+++ b/decision_tree.py
@@ -0,0 +1,184 @@
+import data
+
+training_data = data.learning_data
+
+header = ['color', 'shape', 'weight', 'size', 'name']
+
+
+# funkcja która zwraca listę unikalnych wartości z każdej kolumny
+def uniqie_vals(rows, col):
+ return set([row[col] for row in rows])
+
+
+# zliczamy liczbę wystąpień danego typu w zestawie danych
+def class_counts(rows):
+ counts = {} # label -> 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 c425d69..89f246a 100644
--- a/field.py
+++ b/field.py
@@ -23,6 +23,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()
@@ -30,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)
@@ -46,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 63bd66d..cb61a47 100644
--- a/main.py
+++ b/main.py
@@ -2,12 +2,14 @@ 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
+from mcda import choseProducts
# Inicjalizacja programu i utworzenie obiektu ekrany
def run():
@@ -17,10 +19,13 @@ 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)
+ produsctsFromSupply = choseProducts(5)
+
+ # for row in board:
+ # for field in row:
+ # print(field.cost_of_travel)
path = []
next_step = None
@@ -41,7 +46,9 @@ 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])
+ 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)
@@ -56,17 +63,19 @@ def run():
next_step = path.pop()
else:
next_step = None
- print(next_step, path)
+ # print(next_step, path)
for row in board:
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()
diff --git a/mcda.py b/mcda.py
new file mode 100644
index 0000000..68dd463
--- /dev/null
+++ b/mcda.py
@@ -0,0 +1,99 @@
+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