/* $Header: /users/server/faculty/chow/mci/netrestore/src/MFRREACT/RCS/heuropt.c,v 1.1 1993/12/28 02:37:58 chow Exp $ */ /* Output from p2c, the Pascal-to-C translator */ /* From input file "heuropt.pas" */ /* Heuristic solution tailored for the optimization of spare channels used during RREACT restoration protocol. */ #include "p2c/p2c.h" #define HEUROPT_G #include "heuropt2.h" #include "rmath.h" /* to source the imax function */ Void determine_heuristic(ps, ts, cn) list *ps, *ts; node *cn; { long i, cbw; pathtuple *pt, *tt, *nt; Anyptr edge; long FORLIM; long total, seg_wasted, wasted; float path_eff, seg_eff; long mintmp, maxtmp; pt = (pathtuple *)head_list(ps); while (pt != NULL && cn->tofix > 0) { FORLIM = pt->hc; for (i = 0; i < FORLIM; i++) { mintmp = imin((long)pt->pathvec[i],(long)pt->pathvec[i+1]); maxtmp = imax((long)pt->pathvec[i],(long)pt->pathvec[i+1]); if ((DBG_RREACT) && (DBG_OPT)) printf("DBG: mintmp=%d, maxtmp=%d\n", mintmp, maxtmp); /* pt->bwvec[i] = cn->capacity[imin((long)pt->pathvec[i], (long)pt->pathvec[i + 1]) - 1] [imax((long)pt->pathvec[i], (long)pt->pathvec[i + 1]) - 1]; */ /* The preceding mess simplifies(using mintmp,maxtmp) to the following: */ pt->bwvec[i] = cn->capacity[mintmp - 1][maxtmp - 1]; } cbw = MAXINT; wasted = 0; total = 0; path_eff = 0.0; FORLIM = pt->hc; for (i = 0; i < FORLIM; i++) { cbw = imin(cbw, (long)pt->bwvec[i]); if ((long)pt->bwvec[i] >= pt->bw) seg_wasted = (long)pt->bwvec[i] - pt->bw; else seg_wasted = 0; wasted += seg_wasted; if ((long)pt->bwvec[i] > 0) seg_eff = 1.0 - (seg_wasted/(long)pt->bwvec[i]); else { seg_eff = 0.0; path_eff = 0.0; } path_eff += seg_eff; total += (long)pt->bwvec[i]; } pt->bw = cbw; pt->spares = pt->bw * pt->hc; pt->wbw = (double)pt->bw / cn->tofix; pt->wpl = 2.0 / pt->hc; /* pt->weff = 1.0; */ /* ORIGINAL Weff : forced to 1.0 */ /* pt->weff = 1.0 - (1.0 * wasted)/(1.0 * total); */ pt->weff = path_eff/(1.0 * pt->hc); /* better than . ??? */ /* for i := 0 to pt^.hc-1 do begin if cn^.capacity^[ imin(pt^.pathvec^[i],pt^.pathvec^[i+1]), imax(pt^.pathvec^[i],pt^.pathvec^[i+1]) ] > 0 then weff := weff + (1.0*pt^.bw) / (1.0 * cn^.capacity^[ imin(pt^.pathvec^[i],pt^.pathvec^[i+1]), imax(pt^.pathvec^[i],pt^.pathvec^[i+1]) ] ) else pt^.wpl := 0.0; end; pt^.weff := pt^.weff / pt^.hc; */ /* BESTSOFAR +3, -1 pt->ww = (0.5 * pt->wbw) + (2.0 * pt->wpl) + (5.0 * pt->weff); */ /* BESTSOFAR +2, -0 pt->ww = (0.7 * pt->wbw) + (2.0 * pt->wpl) + (1.0 * pt->weff); */ pt->ww = (0.7 * pt->wbw) + (2.0 * pt->wpl) + (1.0 * pt->weff); /* printf("DBG: WW=%8.5f WBW=%8.5f WPL=%8.5f WEFF=%8.5f\n", pt->ww, pt->wbw, pt->wpl, pt->weff); */ /* pt->ww = pt->wbw * pt->wpl * pt->weff; */ if (pt->bw <= 0) pt->del = true; pt = (pathtuple *)next_list(ps); } pt = (pathtuple *)head_list(ps); while (pt != NULL) { pt->wimp = 0.0; if (!pt->del) { tt = (pathtuple *)head_list(ts); while (tt != NULL) { if (tt->id != pt->id && !tt->del) { edge = head_list(&tt->edges); while (edge != NULL) { if (member_list(&pt->edges, *(long *)edge)) { nt = (pathtuple *)recall_list(ps, tt->id); pt->wimp += nt->ww; } edge = next_list(&tt->edges); } } tt = (pathtuple *)next_list(ts); } pt->wp = pt->ww - pt->wimp; } pt = (pathtuple *)next_list(ps); } unravel(ts); pt = (pathtuple *)head_list(ps); while (pt != NULL) { if (pt->del) { remove_list(ps, pt->id); } else { add_list(ts, (Anyptr)pt, (long)(pt->wp * 1000.0) + pt->id); } pt = (pathtuple *)next_list(ps); } } /* End. */