#EANF#
I have an array of cl objects.Each cl object has an array of strings and
has some string assigned to it. I have an array of Bi objects.Each Bi
object has a producer string and a consumer string. This is what I have to
do. The bi objects show function producer and consumer bindings.The cl
objects show a cluster.Each function can be assigned to one and only one
cluster. Initially all clusters have one function.I am trying to assign
functions to a cluster from the bindings such as the function in the
cluster is either the producer or the consumer of data in the bindings
object.Once a function has been assigned to one cluster then it shouldnt
be assigned to any other cluster.
This is the algo.
For all Bi objects in the Bi array{
For all Cluster objects{
For every function in the current cluster{
if(current function in the current cluster is equal to current Bi's
producer){
Assign current Bi's consumer to current cluster.
Tell all the other Bi objects that this string has been assigned to
this cl object and should'nt be assigned to any other.
}
if(current function in the current cluster is equal to current Bi's
consumer){
Assign current Bi's producer to current cluster.
Tell all the other Bi objects that this string has been assigned to
this cl object and should'nt be assigned to any other.
}
}
}
}
This is the C++ code.
int removeduplicates=0;
for (int s=total_bindings-1; s>=0; s--) {
std::cout<<"The element in bi producer is
"<<bi[s].Producer<<std::endl;
std::cout<<"The element in bi consumer is
"<<bi[s].Consumer<<std::endl;
std::cout<<"The value of bi isproducerassigned is
"<<bi[s].isproducerassigned<<std::endl;
std::cout<<"The value of bi isconsumerassigned is
"<<bi[s].isconsumerassigned<<std::endl;
for(int z=0;z<4;z++){
for(int k=0;k<=cl[z].funcs_top;k++){
removeduplicates=0;
std::cout<<"The element in cl is
"<<cl[z].funcs[k]<<std::endl;
if(cl[z].funcs[k]==bi[s].Producer ){
if( bi[s].isconsumerassigned==false){
cl[z].funcs_top++;
cl[z].funcs[cl[z].funcs_top]=bi[s].Consumer;
std::cout<<"Function merged is "<<bi[s].Consumer<<" The
cluster is "<<z<<std::endl ;
removeduplicates=2;
std::cout<<"Entered clearing condition and the element in
bi[s].consumer is "<<bi[s].Consumer<<std::endl;
bi[s].isconsumerassigned=true;
bi[s].isproducerassigned=true;
}
}
if(cl[z].funcs[k]==bi[s].Consumer){
if(bi[s].isproducerassigned==false){
cl[z].funcs_top++;
cl[z].funcs[cl[z].funcs_top]=bi[s].Producer;
bi[s].isproducerassigned=true;
bi[s].isconsumerassigned=true;
std::cout<<"Function merged is "<<bi[s].Producer<<"The
cluster is "<<z<<std::endl ;
std::cout<<"Entered clearing condition and the
element in bi[s].producer is
"<<bi[s].Producer<<std::endl;
removeduplicates=3;
}
}
if(removeduplicates!=0)
{
for(int v=0;v<total_bindings;v++){
if(removeduplicates==2){
if(bi[v].Consumer==bi[s].Consumer){
bi[v].isconsumerassigned=true;
}
if(bi[v].Producer==bi[s].Consumer){
bi[v].isproducerassigned=true;
}
}else if(removeduplicates==3){
if(bi[v].Consumer==bi[s].Producer ){
bi[v].isconsumerassigned=true;
}
if(bi[v].Producer==bi[s].Producer){
bi[v].isproducerassigned=true;
}
}
}
}
}
}
}
I have four clusters.This is the state of the clusters before the loop.
Cluster 0 init Cluster 1 sum Cluster 2 diff Cluster 3 mul
This the state of the clusters after the loop. Now going to Print
functions merged with cluster 0 init Now going to Print functions merged
with cluster 1 sum Now going to Print functions merged with cluster 2 diff
mul Now going to Print functions merged with cluster 3 mul div sum init
As you can see multiple functions are repeating the clusters.
I know my code is overly complicated so it would be okay if someone can
give their own solution based on my algo.I have been stuck here for the
last 3 days.Someone please help me.
No comments:
Post a Comment