Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float* consensus_iterate(c_node node, int rho, float out[])
- {
- int i = 0;
- float cost;
- float z[ID_ARRAY_LENGHT], d_u[ID_ARRAY_LENGHT], d_bli[ID_ARRAY_LENGHT];
- float d_b0[ID_ARRAY_LENGHT], d_b1[ID_ARRAY_LENGHT], d_l0[ID_ARRAY_LENGHT], d_l1[ID_ARRAY_LENGHT], d_aux = 0;
- out[ID_ARRAY_LENGHT] = 100000;
- //init outputs-[d_best cost]
- for(i = 0; i < ID_ARRAY_LENGHT; i++)
- {
- out[i] = -1;
- z[i] = node.d_av[i] - node.y[i]/rho - node.c[i]/rho;
- d_aux = d_aux + z[i]*node.k[i];
- d_b0[i] = z[i]/rho;
- d_b1[i] = d_b0[i];
- d_u[i] = z[i]/rho;
- if(ID_ARRAY[i] == own_id)
- {
- }
- }
- d_b0[node.index] = 0;
- d_b1[node.index] = 100;
- for ( i = 0; i < ID_ARRAY_LENGHT; i++)
- {
- d_bli[i] = (1/rho)*z[i] - node.k[i]/node.n[i]*(node.o-node.L+(1/rho)*d_aux);
- 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);
- 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);
- }
- d_l0[node.index] = 0;
- d_l1[node.index] = 100;
- if(check_feasability(node, d_u))
- {
- cost = evaluate_cost(node, d_u, rho);
- if(cost < out[ID_ARRAY_LENGHT])
- for ( i = 0; i < ID_ARRAY_LENGHT; i++)
- {
- out[i] = d_u[i];
- }
- out[ID_ARRAY_LENGHT]= cost;
- }
- // compute cost and if best store new optimum
- if(check_feasibility(node, d_bli))
- {
- cost = evaluate_cost(node, d_bli,rho);
- if (cost < out[ID_ARRAY_LENGHT])
- {
- for ( i = 0; i < ID_ARRAY_LENGHT; i++)
- {
- out[i] = d_bli[i];
- }
- out[ID_ARRAY_LENGHT] = cost;
- }
- }
- // compute cost and if best store new optimum
- if(check_feasibility(node, d_b0))
- {
- cost = evaluate_cost(node, d_b0,rho);
- if(cost < out[ID_ARRAY_LENGHT])
- {
- for ( i = 0; i < ID_ARRAY_LENGHT; i++)
- {
- out[i] = d_b0[i];
- }
- out[ID_ARRAY_LENGHT]= cost;
- }
- }
- //check feasibility of minimum constrained to 100 boundary
- if(check_feasibility(node, d_b1))
- {
- cost = evaluate_cost(node, d_b1,rho);
- if(cost < out[ID_ARRAY_LENGHT])
- {
- for ( i = 0; i < ID_ARRAY_LENGHT; i++)
- {
- out[i] = d_b1[i];
- }
- out[ID_ARRAY_LENGHT] = cost;
- }
- }
- //compute cost and if best store new optimum
- if(check_feasibility(node, d_l0))
- {
- cost = evaluate_cost(node, d_l0,rho);
- if(cost < out[ID_ARRAY_LENGHT])
- {
- for ( i = 0; i < ID_ARRAY_LENGHT; i++)
- {
- out[i] = d_l0[i];
- }
- out[ID_ARRAY_LENGHT] = cost;
- }
- }
- //compute cost and if best store new optimum
- if(check_feasibility(node, d_l1))
- {
- cost = evaluate_cost(node, d_l1,rho);
- if(cost < out[ID_ARRAY_LENGHT])
- {
- for ( i = 0; i < ID_ARRAY_LENGHT; i++)
- {
- out[i] = d_l1[i];
- }
- out[ID_ARRAY_LENGHT] = cost;
- }
- }
- return out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement