static void restoreBalance(AVLTreeT *tree, TreeNodeT *node, BalancingTypeT balance) { TreeNodeT* parent; int node_balance, stop_criterion; stop_criterion = stopCriterion(balance); while (node != NULL) { fixTreeHeight(node); node_balance = nodeBalanceFlag(node); parent = node->parent; if (abs(node_balance) == stop_criterion) return; else if (node_balance == -2) { if (nodeBalanceFlag(node->r_child) > 0) smallRightRotate(tree, node->r_child); smallLeftRotate(tree, node); } else if (node_balance == 2) { if (nodeBalanceFlag(node->l_child) < 0) smallLeftRotate(tree, node->l_child); smallRightRotate(tree, node); } node = parent; } }
void FMMMLayout :: call_FORCE_CALCULATION_step(Graph& G,NodeArray<NodeAttributes>&A, EdgeArray<EdgeAttributes>& E,int act_level, int max_level) { const int ITERBOUND = 10000;//needed to guarantee termination if //stopCriterion() == scThreshold if(G.numberOfNodes() > 1) { int iter = 1; int max_mult_iter = get_max_mult_iter(act_level,max_level,G.numberOfNodes()); double actforcevectorlength = threshold() + 1; NodeArray<DPoint> F_rep(G); //stores rep. forces NodeArray<DPoint> F_attr(G); //stores attr. forces NodeArray<DPoint> F (G); //stores resulting forces NodeArray<DPoint> last_node_movement(G);//stores the force vectors F of the last //iterations (needed to avoid oszilations) set_average_ideal_edgelength(G,E);//needed for easy scaling of the forces make_initialisations_for_rep_calc_classes(G); while( ((stopCriterion() == scFixedIterations)&&(iter <= max_mult_iter)) || ((stopCriterion() == scThreshold)&&(actforcevectorlength >= threshold())&& (iter <= ITERBOUND)) || ((stopCriterion() == scFixedIterationsOrThreshold)&&(iter <= max_mult_iter) && (actforcevectorlength >= threshold())) ) {//while calculate_forces(G,A,E,F,F_attr,F_rep,last_node_movement,iter,0); if(stopCriterion() != scFixedIterations) actforcevectorlength = get_average_forcevector_length(G,F); iter++; }//while if((act_level == 0)) call_POSTPROCESSING_step(G,A,E,F,F_attr,F_rep,last_node_movement); deallocate_memory_for_rep_calc_classes(); } }
Solution GRASP_findPath(CitiesData cities){ Solution bestSolution; Solution solution; solution = greedyRandomizedConstruction(cities); bestSolution = solution; printf("num_cities = %d\nk = %d\n",cities.count+1,cities.k); printf("alpha = %f\niterations = %d\n\n",GRASP_ALPHA,GRASP_MAX_ITERATIONS); printf("starting solution distance: %f\n",getRoutesLength(solution)); int i; for(int i = 1; !stopCriterion(i); i++){ // greedy randomized construction solution = greedyRandomizedConstruction(cities); // neighborhood search //solution = localSearch(solution); // po dodaniu miasta sie optymalizuje double gain = getRoutesLength(bestSolution) - getRoutesLength(solution); if(gain > 0) printf("\n[new best in round %d.\tgained: %f] ",i,gain); else{ float percentDone = (i * 100.0)/GRASP_MAX_ITERATIONS; if((i)%(int(GRASP_MAX_ITERATIONS/20)) == 0) printf("%2.0f%c ",percentDone,'%'); } bestSolution = getBetterSolution(solution,bestSolution); if(gain <= 0.0)destroySolution(solution); } printf("\n"); return bestSolution; }
void FMMMLayout :: initialize_all_options() { //setting high level options useHighLevelOptions(false); pageFormat(pfSquare); unitEdgeLength(100); newInitialPlacement(false); qualityVersusSpeed(qvsBeautifulAndFast); //setting low level options //setting general options randSeed(100);edgeLengthMeasurement(elmBoundingCircle); allowedPositions(apInteger);maxIntPosExponent(40); //setting options for the divide et impera step pageRatio(1.0);stepsForRotatingComponents(10); tipOverCCs(toNoGrowingRow);minDistCC(100); presortCCs(psDecreasingHeight); //setting options for the multilevel step minGraphSize(50);galaxyChoice(gcNonUniformProbLowerMass);randomTries(20); maxIterChange(micLinearlyDecreasing);maxIterFactor(10); initialPlacementMult(ipmAdvanced); //setting options for the force calculation step forceModel(fmNew);springStrength(1);repForcesStrength(1); repulsiveForcesCalculation(rfcNMM);stopCriterion(scFixedIterationsOrThreshold); threshold(0.01);fixedIterations(30);forceScalingFactor(0.05); coolTemperature(false);coolValue(0.99);initialPlacementForces(ipfRandomRandIterNr); //setting options for postprocessing resizeDrawing(true);resizingScalar(1);fineTuningIterations(20); fineTuneScalar(0.2);adjustPostRepStrengthDynamically(true); postSpringStrength(2.0);postStrengthOfRepForces(0.01); //setting options for different repulsive force calculation methods frGridQuotient(2); nmTreeConstruction(rtcSubtreeBySubtree);nmSmallCell(scfIteratively); nmParticlesInLeaves(25); nmPrecision(4); }