[Pntool-developers] SF.net SVN: pntool:[68] pnheaders
Brought to you by:
compaqdrew,
miordache
From: <mio...@us...> - 2009-06-17 23:59:17
|
Revision: 68 http://pntool.svn.sourceforge.net/pntool/?rev=68&view=rev Author: miordache Date: 2009-06-17 23:58:11 +0000 (Wed, 17 Jun 2009) Log Message: ----------- Updated some pns.h types and added a function to copy pn objects Modified Paths: -------------- pnheaders/pnexample.c pnheaders/pns.c pnheaders/pns.h Modified: pnheaders/pnexample.c =================================================================== --- pnheaders/pnexample.c 2009-06-17 23:32:48 UTC (rev 67) +++ pnheaders/pnexample.c 2009-06-17 23:58:11 UTC (rev 68) @@ -5,7 +5,7 @@ /* Declaring pn objects */ - pns pn_p, pn_s, pn; + pns pn_p, pn_s, pn_s2, pn, pn2; /* Petri nets can be initialized using the incidence matrix */ @@ -101,7 +101,8 @@ /* Flags are set as follows. */ - updatepn(&pn, "unobservable", 0);/*marks transition 0 unobservable*/ + updatepn(&pn, "unobservable nondeterministic", 0, 1); + /* marks transition 0 unobservable and place 1 as nondeterministic */ updatepn(&pn, "live uncontrollable uncontrollable", 0, 0, 2); /* The line above sets the "live" and "uncontrollable" flags of @@ -132,11 +133,16 @@ placed in the pns object, it is not copied. Thus, alist is deallocated when the pns object is deallocated with the function deallocpn. */ + /* To create a copy */ + + pn2 = copypn(&pn); + /* To deallocate a pn object use deallocpn */ deallocpn(&pn_p); deallocpn(&pn_s); deallocpn(&pn); + deallocpn(&pn2); return 0; } Modified: pnheaders/pns.c =================================================================== --- pnheaders/pns.c 2009-06-17 23:32:48 UTC (rev 67) +++ pnheaders/pns.c 2009-06-17 23:58:11 UTC (rev 68) @@ -519,6 +519,74 @@ } + +pns copypn(pns *src) { + pns dst; + arcs *pa; const arcs *pb; + struct placelist *pd; const struct placelist *ps; + int i; + + dst = createpn("pnum tnum mDm mDp", src->pnum, src->tnum, src->out, src->in); + if(src->marking) updatepn(&dst, "m0", src->marking); + if(src->C) updatepn(&dst, "C", src->C); + if(src->place_name) + for(i = 0; i < src->pnum; i++) + if(src->place_name[i]) + updatepn(&dst, "place_name", i, src->place_name[i]); + if(src->segment) + for(i = 0; i < src->pnum; i++) + if(src->segment[i]) + updatepn(&dst, "segment", i, src->segment[i]); + if(src->select) + for(i = 0; i < src->pnum; i++) + if(src->select[i]) + updatepn(&dst, "select", i, src->select[i]); + if(src->trans_name) + for(i = 0; i < src->tnum; i++) + if(src->trans_name[i]) + updatepn(&dst, "trans_name", i, src->trans_name[i]); + if(src->t) { + dst.t = tcalloc(dst.tnum, sizeof(src->t[0])); + for(i = 0; i < src->tnum; i++) + dst.t[i] = src->t[i]; + } + if(src->p) { + dst.p = tcalloc(dst.pnum, sizeof(src->p[0])); + for(i = 0; i < src->pnum; i++) + dst.p[i] = src->p[i]; + } + if(src->arc_list) { /* copy the list of arcs */ + dst.arc_list = tcalloc(dst.tnum, sizeof(*(dst.arc_list))); + for(i = 0; i < src->tnum; i++) { + if(src->arc_list[i]) { + dst.arc_list[i] = tmalloc(sizeof(*(dst.arc_list[0]))); + for(pa = dst.arc_list[i], pb = src->arc_list[i]; pa; pa = pa->next) { + *pa = *pb; + if(pb->condition) { + pa->condition = tmalloc(sizeof(char)*(strlen(pb->condition) + 1)); + strcpy(pa->condition, pb->condition); + } + if(pb->out_places) { /* copy out_places */ + pa->out_places = tmalloc(sizeof(*(pa->out_places))); + for(pd = pa->out_places, ps = pb->out_places; pd; pd = pd->next) { + *pd = *ps; + ps = ps->next; + if(ps) /* else, pd->next is already 0 */ + pd->next = tmalloc(sizeof(*pd)); + } + } + pb = pb->next; + if(pb) + pa->next = tmalloc(sizeof(*pa)); /* else, pa->next already 0 */ + } + } + } + } + + return dst; +} + + void deallocpn(pns *pn) { int i, pnum, tnum; pnum = pn->pnum; Modified: pnheaders/pns.h =================================================================== --- pnheaders/pns.h 2009-06-17 23:32:48 UTC (rev 67) +++ pnheaders/pns.h 2009-06-17 23:58:11 UTC (rev 68) @@ -1,5 +1,5 @@ -/* PNS.H -- Version 2 (05/21/2009) +/* PNS.H -- Version 2.1 (06/17/2009) Please refer to input2.sp describing the specification format for background information on the meaning of the data structures. */ @@ -165,14 +165,17 @@ - mD: matrix type expected. Represents the incidence matrix. - mDm: matrix type expected. Represents the output matrix. - mDp: matrix type expected. Represents the input matrix. + - arcs: int and arcs* types expected, in this order. The integer argument identifies the transition. The arcs* argument is placed in the arcs_list element of the pns object. Therefore, do not deallocate it! All the 'next' pointers in the arcs* argument must be zero, unless some other element follows. + - C: int* type expected. The parameter is the capacity vector. - label: int* type expected. Represents transition labels. - live: int type expected. The parameter identifies the transition that should be live. + - m0: int* type expected. The parameter is the initial marking vector. - nondeterministic: int type expected. The parameter identifies the place that should be marked as nondeterministic. - place_name: int and char*. That is, two arguments are expected in This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |