Skip to content

Commit

Permalink
packing check more than one level neighbors after first component pla…
Browse files Browse the repository at this point in the history
…cing
  • Loading branch information
nasimsaleh committed Sep 2, 2019
1 parent d063ac4 commit 43916e1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 6 deletions.
26 changes: 23 additions & 3 deletions cytoscape-layout-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ var Grid = function () {

_createClass(Grid, [{
key: 'getDirectNeighbors',
value: function getDirectNeighbors(cells) {
value: function getDirectNeighbors(cells, level) {
var resultPoints = [];
if (cells.length == 0) {
for (var i = 0; i < this.width; i++) {
Expand All @@ -223,6 +223,20 @@ var Grid = function () {
}
}
}
var startIndex = 0;
var endIndex = resultPoints.length - 1;

for (var i = 2; i <= level; i++) {

if (endIndex >= startIndex) {
for (var j = startIndex; j <= endIndex; j++) {
resultPoints = resultPoints.concat(this.getCellNeighbors(resultPoints[j].x, resultPoints[j].y));
}
}

startIndex = endIndex + 1;
endIndex = resultPoints.length - 1;
}
} else {
cells.forEach(function (cell) {
resultPoints = resultPoints.concat(this.getCellNeighbors(cell.x, cell.y));
Expand Down Expand Up @@ -873,7 +887,12 @@ var layoutUtilities = function layoutUtilities(cy, options) {
var cells = [];
var resultLocation = {};
while (!placementFound) {
cells = mainGrid.getDirectNeighbors(cells);
if (i == 1) {
cells = mainGrid.getDirectNeighbors(cells, Math.ceil(Math.max(polyominos[i].width, polyominos[i].height) / 2));
} else {
cells = mainGrid.getDirectNeighbors(cells, 1);
}

cells.forEach(function (cell) {
if (mainGrid.tryPlacingPolyomino(polyominos[i], cell.x, cell.y)) {
placementFound = true;
Expand Down Expand Up @@ -971,7 +990,8 @@ var __WEBPACK_AMD_DEFINE_RESULT__;
offset: 20,
desiredAspectRatio: 1,
polyominoGridSizeFactor: 1,
utilityFunction: 1 // Maximize adjusted Fullness 2: maximizes weighted function of fullness and aspect ratio
utilityFunction: 1, // Maximize adjusted Fullness 2: maximizes weighted function of fullness and aspect ratio
componentSpacing: 0
};

var layoutUtilities = __webpack_require__(2);
Expand Down
32 changes: 31 additions & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,39 @@
offset: 20,
desiredAspectRatio: 1,
polyominoGridSizeFactor: 1,
utilityFunction: 1 // Maximize adjusted Fullness 2: maximizes weighted function of fullness and aspect ratio
utilityFunction: 1, // Maximize adjusted Fullness 2: maximizes weighted function of fullness and aspect ratio
componentSpacing : 0
};


/* function extend(defaults, options) {
var obj = {};
for (var i in defaults) {
obj[i] = defaults[i];
}
for (var i in options) {
if(i == "desiredAspectRatio"){
var value = options[i];
if(!isNaN(value))
{
if(value >= 0 && value <= 20){
obj[i] = options[i];
}else if(value < 0){
obj[i] = 0
}else{
obj[i] = 20
}
}
}else{
obj[i] = options[i];
}
}
return obj;
}; */
var layoutUtilities = require("./layout-utilities");

cytoscape('core', 'layoutUtilities', function (opts) {
Expand All @@ -28,6 +57,7 @@
return getScratch(cy).instance;
}


$.extend(true, options, opts);

function getScratch(eleOrCy) {
Expand Down
3 changes: 2 additions & 1 deletion src/core/layout-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ var layoutUtilities = function (cy, options) {
var cells = [];
var resultLocation = {};
while(!placementFound){
cells = mainGrid.getDirectNeighbors(cells);

cells = mainGrid.getDirectNeighbors(cells, Math.ceil(Math.max(polyominos[i].width,polyominos[i].height) / 2));
cells.forEach(function(cell){
if(mainGrid.tryPlacingPolyomino(polyominos[i], cell.x, cell.y)){
placementFound = true;
Expand Down
18 changes: 17 additions & 1 deletion src/core/polyomino-packing.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Grid{
}

//function given a list of cells it returns the direct unvisited unoccupied neighboring cells
getDirectNeighbors(cells){
getDirectNeighbors(cells, level){
var resultPoints = [];
if(cells.length == 0){
for(var i = 0 ; i< this.width;i++){
Expand All @@ -71,6 +71,22 @@ class Grid{
}
}
}
var startIndex = 0 ;
var endIndex = resultPoints.length -1 ;

for(var i = 2 ; i<=level ; i++){

if(endIndex >= startIndex){
for(var j = startIndex ; j<= endIndex ; j++){
resultPoints = resultPoints.concat(this.getCellNeighbors(resultPoints[j].x,resultPoints[j].y));
}
}

startIndex = endIndex +1;
endIndex = resultPoints.length - 1;

}

}else{
cells.forEach(function(cell){
resultPoints = resultPoints.concat(this.getCellNeighbors(cell.x,cell.y));
Expand Down

0 comments on commit 43916e1

Please sign in to comment.