function adjustCrossing(internal, external)
			 {
			 	var targetWithin = Math.round(internal * internal * self.N * self.N);
			 	var targetCross = Math.round(external * external * self.N * self.N); 

			 	// count the current within and crossings in the generated data
			 	var crossCount = getCrossCount();

			 	while(crossCount > targetCross)
			 	{
			 		// pick a random link 
			 		var index = Math.floor(Math.random() * randLinks.length);
			 		var srcId = (randLinks[index].source > 0)? randLinks[index].source-1 : 0; 
			 		var dstId = (randLinks[index].target > 0)? randLinks[index].target-1 : 0;
			 		var srcLoc = randNodes[srcId].location; 
			 		var dstLoc = randNodes[dstId].location;
			 		if(srcLoc !== dstLoc)
			 		{
			 			// choose between source and destination
			 			var updateTarget; 
			 			var withinSrc = getWithinNodeCount(srcLoc);
			 			var withinDst = getWithinNodeCount(dstLoc);
			 			var which = Math.floor(Math.random() * 2); 
			 			if(which === 1)
			 				randNodes[srcId].location = randNodes[dstId].location;
			 			else 
			 				randNodes[dstId].location = randNodes[srcId].location;
			 				
			 		}
			 		crossCount = getCrossCount();	
			 	}
			 	console.log('final Cross count = ' + crossCount); 
			 	var withinCount = randLinks.length - crossCount;
			 	console.log('Within count = ' + withinCount); 

			 	crossCount = getCrossCount();
			 }
// Modify connections to adjust to within and cross-compartment densities
Modify connections to adjust to within and cross-compartment densities
Modify connections to adjust to within and cross - compartment densities
function adjustCrossing(internal, external)
			 {
			 	var targetWithin = Math.round(internal * internal * self.N * self.N);
			 	var targetCross = Math.round(external * external * self.N * self.N); 
			 	var crossCount = getCrossCount();
			 	while(crossCount > targetCross)
			 	{
			 		var index = Math.floor(Math.random() * randLinks.length);
			 		var srcId = (randLinks[index].source > 0)? randLinks[index].source-1 : 0; 
			 		var dstId = (randLinks[index].target > 0)? randLinks[index].target-1 : 0;
			 		var srcLoc = randNodes[srcId].location; 
			 		var dstLoc = randNodes[dstId].location;
			 		if(srcLoc !== dstLoc)
			 		{
			 			var updateTarget; 
			 			var withinSrc = getWithinNodeCount(srcLoc);
			 			var withinDst = getWithinNodeCount(dstLoc);
			 			var which = Math.floor(Math.random() * 2); 
			 			if(which === 1)
			 				randNodes[srcId].location = randNodes[dstId].location;
			 			else 
			 				randNodes[dstId].location = randNodes[srcId].location;
			 		}
			 		crossCount = getCrossCount();	
			 	}
			 	console.log('final Cross count = ' + crossCount); 
			 	var withinCount = randLinks.length - crossCount;
			 	console.log('Within count = ' + withinCount); 
			 	crossCount = getCrossCount();
			 }
function adjustCrossing ( internal , external ) { var targetWithin = Math . round ( internal * internal * self . N * self . N ) ; var targetCross = Math . round ( external * external * self . N * self . N ) ; var crossCount = getCrossCount ( ) ; while ( crossCount > targetCross ) { var index = Math . floor ( Math . random ( ) * randLinks . length ) ; var srcId = ( randLinks [ index ] . source > 0 ) ? randLinks [ index ] . source - 1 : 0 ; var dstId = ( randLinks [ index ] . target > 0 ) ? randLinks [ index ] . target - 1 : 0 ; var srcLoc = randNodes [ srcId ] . location ; var dstLoc = randNodes [ dstId ] . location ; if ( srcLoc !== dstLoc ) { var updateTarget ; var withinSrc = getWithinNodeCount ( srcLoc ) ; var withinDst = getWithinNodeCount ( dstLoc ) ; var which = Math . floor ( Math . random ( ) * 2 ) ; if ( which === 1 ) randNodes [ srcId ] . location = randNodes [ dstId ] . location ; else randNodes [ dstId ] . location = randNodes [ srcId ] . location ; } crossCount = getCrossCount ( ) ; } console . log ( 'final Cross count = ' + crossCount ) ; var withinCount = randLinks . length - crossCount ; console . log ( 'Within count = ' + withinCount ) ; crossCount = getCrossCount ( ) ; }
Modify connections to adjust to within and cross-compartment densities
Modify connections to adjust to within and cross - compartment densities
// count the current within and crossings in the generated data // pick a random link  // choose between source and destination