Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. float* consensus_iterate(c_node node, int rho, float out[])
  2. {
  3. int i = 0;
  4. float cost;
  5. float z[ID_ARRAY_LENGHT], d_u[ID_ARRAY_LENGHT], d_bli[ID_ARRAY_LENGHT];
  6. float d_b0[ID_ARRAY_LENGHT], d_b1[ID_ARRAY_LENGHT], d_l0[ID_ARRAY_LENGHT], d_l1[ID_ARRAY_LENGHT], d_aux = 0;
  7.  
  8. out[ID_ARRAY_LENGHT] = 100000;
  9.  
  10. //init outputs-[d_best cost]
  11. for(i = 0; i < ID_ARRAY_LENGHT; i++)
  12. {
  13. out[i] = -1;
  14. z[i] = node.d_av[i] - node.y[i]/rho - node.c[i]/rho;
  15. d_aux = d_aux + z[i]*node.k[i];
  16. d_b0[i] = z[i]/rho;
  17. d_b1[i] = d_b0[i];
  18. d_u[i] = z[i]/rho;
  19. if(ID_ARRAY[i] == own_id)
  20. {
  21.  
  22. }
  23. }
  24. d_b0[node.index] = 0;
  25. d_b1[node.index] = 100;
  26.  
  27.  
  28. for ( i = 0; i < ID_ARRAY_LENGHT; i++)
  29. {
  30. d_bli[i] = (1/rho)*z[i] - node.k[i]/node.n[i]*(node.o-node.L+(1/rho)*d_aux);
  31. d_l0[i] = (1/rho)*z[i] - (1/node.m)*node.k[i]*(node.o-node.L) + (node.m/rho)*node.k[i]*(node.k[node.index]*z[node.index]-d_aux);
  32. d_l1[i] = (1/rho)*z[i] - (1/node.m)*node.k[i]*(node.o-node.L+100*node.k[node.index]) + (node.m/rho)*node.k[i]*(node.k[node.index]*z[node.index]-d_aux);
  33.  
  34. }
  35. d_l0[node.index] = 0;
  36. d_l1[node.index] = 100;
  37.  
  38.  
  39. if(check_feasability(node, d_u))
  40. {
  41. cost = evaluate_cost(node, d_u, rho);
  42. if(cost < out[ID_ARRAY_LENGHT])
  43. for ( i = 0; i < ID_ARRAY_LENGHT; i++)
  44. {
  45. out[i] = d_u[i];
  46. }
  47. out[ID_ARRAY_LENGHT]= cost;
  48. }
  49.  
  50. // compute cost and if best store new optimum
  51. if(check_feasibility(node, d_bli))
  52. {
  53. cost = evaluate_cost(node, d_bli,rho);
  54. if (cost < out[ID_ARRAY_LENGHT])
  55. {
  56. for ( i = 0; i < ID_ARRAY_LENGHT; i++)
  57. {
  58. out[i] = d_bli[i];
  59. }
  60. out[ID_ARRAY_LENGHT] = cost;
  61. }
  62. }
  63.  
  64. // compute cost and if best store new optimum
  65. if(check_feasibility(node, d_b0))
  66. {
  67. cost = evaluate_cost(node, d_b0,rho);
  68. if(cost < out[ID_ARRAY_LENGHT])
  69. {
  70. for ( i = 0; i < ID_ARRAY_LENGHT; i++)
  71. {
  72. out[i] = d_b0[i];
  73. }
  74. out[ID_ARRAY_LENGHT]= cost;
  75. }
  76. }
  77.  
  78. //check feasibility of minimum constrained to 100 boundary
  79. if(check_feasibility(node, d_b1))
  80. {
  81. cost = evaluate_cost(node, d_b1,rho);
  82. if(cost < out[ID_ARRAY_LENGHT])
  83. {
  84. for ( i = 0; i < ID_ARRAY_LENGHT; i++)
  85. {
  86. out[i] = d_b1[i];
  87. }
  88. out[ID_ARRAY_LENGHT] = cost;
  89. }
  90. }
  91.  
  92. //compute cost and if best store new optimum
  93. if(check_feasibility(node, d_l0))
  94. {
  95. cost = evaluate_cost(node, d_l0,rho);
  96. if(cost < out[ID_ARRAY_LENGHT])
  97. {
  98. for ( i = 0; i < ID_ARRAY_LENGHT; i++)
  99. {
  100. out[i] = d_l0[i];
  101. }
  102. out[ID_ARRAY_LENGHT] = cost;
  103. }
  104. }
  105.  
  106. //compute cost and if best store new optimum
  107. if(check_feasibility(node, d_l1))
  108. {
  109. cost = evaluate_cost(node, d_l1,rho);
  110. if(cost < out[ID_ARRAY_LENGHT])
  111. {
  112. for ( i = 0; i < ID_ARRAY_LENGHT; i++)
  113. {
  114. out[i] = d_l1[i];
  115. }
  116. out[ID_ARRAY_LENGHT] = cost;
  117. }
  118. }
  119.  
  120.  
  121. return out;
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement