Set Covering : Runtime hang\error at function call in c
Posted
by
EnthuCrazy
on Programmers
See other posts from Programmers
or by EnthuCrazy
Published on 2011-11-24T03:51:30Z
Indexed on
2011/11/24
10:21 UTC
Read the original article
Hit count: 342
I am implementing a set covering application which uses cover function
int cover(set *skill_list,set *player_list,set *covering)
Suppose skill_set={a,b,c,d,e}, player_list={s1,s2,s3} then output coverin ={s1,s3} where say s1={a,b,c}, s3={d,e} and s2={b,d}.
Now when I am calling this function it's hanging at run (set_cover.exe stopped working).
Here is my cover function:
typedef struct Spst_{
void *key;
set *st;
}Spst;
int cover(set *skill_list,set *player_list,set *covering)
{
Liste *member,*max_member;
Spst *subset;
set *intersection;
void **data;
int max_size;
set_init(covering); //to initialize set covering initially
while(skill_list->size>0&&player_list->size>0)
{
max_size=0;
for(member=player_list->head;member!=NULL;member=member->next)
{
if(set_intersection(intersection,((Spst *)(member->data))->st,skill_list)!=0)
return -1;
if(intersection->size>max_size)
{
max_member=member;
max_size=intersection->size;
}
set_destroy(intersection); //at the end of iteration
}
if(max_size==0) //to check for no covering
return -1;
subset=(Spst *)max_member->data; //to insert max subset from play list to covering set
set_inselem(covering,subset);
for(member=(((Spst *)max_member->data)->st->head);member!=NULL;member=member->next) //to rem elem from skill list
{
data=(void **)member->data;
set_remelem(skill_list,data);
}
set_remelem(player_list,(void **)subset); //to rem subset from set of subsets play list
}
if(skill_list->size>0)
return -1;
return 0;
}
Now assuming I have defined three set type sets(as stated above) and calling from main as
cover(skills,subsets,covering);=> runtime hang Here
Please give inputs on the missing link in this or the prerequisites for a proper call to this function type required.
EDIT: Assume other functions used in cover are tested and working fine.
© Programmers or respective owner