cencen_cj

15 Reputation

2 Badges

5 years, 136 days

MaplePrimes Activity


These are replies submitted by cencen_cj

Thanks for your time and patience@tomleslie. I hope you have refreshed morning.

It did take forever as the x[i] and y[i] have not been rounded to integer yet. As the inputs to f() procedure, they should be integer by design. 

I will revise my codes regarding the check function. It is a bit lousy. Thanks:).

 

 

untitled_folder.zip@tomleslie 

Hi I have attached the txt files. The problem might lie in the if statement :

 if x[i]<0 or y[i]<0 or x[i]>50 or y[i]>50 or x[i]>y[i] then, when program terminated and reported many level of recursion error at this condition statement.

Conceptually it should be correct. I have no clue what went wrong. Please kindly give me a hint.

Thanks,

Best,

Jie

Hi Thanks very much for your reply@Carl Love.  lines.Untitled_JIE.mw

Please kindly find attached the worksheet. It used to run well but somehow today it reported too many recursion errors when I try to call f1(50). Would much appreciate it if you could give me a hint. Thanks again!
 

restart; with(LinearAlgebra); with(plots, textplot, display); with(PolynomialTools); with(RootFinding); with(Statistics); with(inttrans); with(ArrayTools); Digits := 100

[textplot, display]

(1)

currentdir()

"/Users/min/Dropbox/Durham/Dib-Thresholded_Queue"

(2)

f := proc (x1, x2)::float; a1temp := readdata("a1.txt", float); a2temp := readdata("a2.txt", float); a3temp := readdata("a3.txt", float); for i from 0 to Size(a1temp, 2)-1 do a1[i] := a1temp[i+1]; a2[i] := a2temp[i+1]; a3[i] := a3temp[i+1] end do; a1bartemp := readdata("a1bar.txt", float); a2bartemp := readdata("a2bar.txt", float); a3bartemp := readdata("a3bar.txt", float); for i from 0 to Size(a1bartemp, 2)-1 do a1bar[i] := a1bartemp[i+1]; a2bar[i] := a2bartemp[i+1]; a3bar[i] := a3bartemp[i+1] end do; L1 := x1; L2 := x2; L3 := 50; power1 := 10000000; power2 := 150000000; power3 := 200000000; power4 := 45; unassign('KConst'); unassign('p'); unassign('TotalPower'); rate := readdata("servrate.txt", float); mu1 := rate[1]; mu2 := rate[2]; mu3 := rate[3]; for i from 0 to L3+1 do p[i] := 0 end do; p[0] := KConst; p[1] := p[0]*(1-a1[0])/a1[0]; for j to L1-1 do p[j+1] := (p[j]-p[0]*a1[j]-add(p[i]*a1[j-i+1], i = 1 .. j))/a1[0] end do; for j from L1 to L2-1 do p[j+1] := (p[j]-p[0]*a1[j]-add(p[i]*a1[j-i+1], i = 1 .. L1)-add(p[i]*a2[j-i+1], i = L1+1 .. j))/a2[0] end do; for j from L2 to L3-1 do p[j+1] := (p[j]-p[0]*a1[j]-add(p[i]*a1[j-i+1], i = 1 .. L1)-add(p[i]*a2[j-i+1], i = L1+1 .. L2)-add(p[i]*a3[j-i+1], i = L2+1 .. j))/a3[0] end do; p[L3+1] := (p[0]*a1bar[L3+1]+add(p[i]*a1bar[L3-i+2], i = 1 .. L1)+add(p[i]*a2bar[L3-i+2], i = L1+1 .. L2)+add(p[i]*a3bar[L3-i+2], i = L2+1 .. L3))/(1-a3bar[1]); SumOfAllProb := add(p[i], i = 0 .. L3+1); piplus0 := fsolve(SumOfAllProb = 1, KConst); p[0] := piplus0; p[1] := p[0]*(1-a1[0])/a1[0]; for j to L1-1 do p[j+1] := (p[j]-p[0]*a1[j]-add(p[i]*a1[j-i+1], i = 1 .. j))/a1[0] end do; for j from L1 to L2-1 do p[j+1] := (p[j]-p[0]*a1[j]-add(p[i]*a1[j-i+1], i = 1 .. L1)-add(p[i]*a2[j-i+1], i = L1+1 .. j))/a2[0] end do; for j from L2 to L3-1 do p[j+1] := (p[j]-p[0]*a1[j]-add(p[i]*a1[j-i+1], i = 1 .. L1)-add(p[i]*a2[j-i+1], i = L1+1 .. L2)-add(p[i]*a3[j-i+1], i = L2+1 .. j))/a3[0] end do; p[L3+1] := (p[0]*a1bar[L3+1]+add(p[i]*a1bar[L3-i+2], i = 1 .. L1)+add(p[i]*a2bar[L3-i+2], i = L1+1 .. L2)+add(p[i]*a3bar[L3-i+2], i = L2+1 .. L3))/(1-a3bar[1]); TotalPower := power1*add(p[i], i = 1 .. L1-1)+power2*add(p[i], i = L1 .. L2-1)+power3*add(p[i], i = L2 .. L3-1); MeanSysLength := add(i*p[i], i = 0 .. L3+1); lambda := 125; if 0 <= MeanSysLength and MeanSysLength <= L1 then Ave_Ene := power1 end if; if L1 < MeanSysLength and MeanSysLength <= L2 then Ave_Ene := power2 end if; if L2 < MeanSysLength and MeanSysLength <= 50 then Ave_Ene := power3 end if; MeanWait := MeanSysLength/(lambda*(1-p[L3+1])); return Ave_Ene, MeanWait end proc;

Warning, `a1temp` is implicitly declared local to procedure `f`

 

Warning, `a2temp` is implicitly declared local to procedure `f`

 

Warning, `a3temp` is implicitly declared local to procedure `f`

 

Warning, `i` is implicitly declared local to procedure `f`

 

Warning, `a1` is implicitly declared local to procedure `f`

 

Warning, `a2` is implicitly declared local to procedure `f`

 

Warning, `a3` is implicitly declared local to procedure `f`

 

Warning, `a1bartemp` is implicitly declared local to procedure `f`

 

Warning, `a2bartemp` is implicitly declared local to procedure `f`

 

Warning, `a3bartemp` is implicitly declared local to procedure `f`

 

Warning, `a1bar` is implicitly declared local to procedure `f`

 

Warning, `a2bar` is implicitly declared local to procedure `f`

 

Warning, `a3bar` is implicitly declared local to procedure `f`

 

Warning, `L1` is implicitly declared local to procedure `f`

 

Warning, `L2` is implicitly declared local to procedure `f`

 

Warning, `L3` is implicitly declared local to procedure `f`

 

Warning, `power1` is implicitly declared local to procedure `f`

 

Warning, `power2` is implicitly declared local to procedure `f`

 

Warning, `power3` is implicitly declared local to procedure `f`

 

Warning, `power4` is implicitly declared local to procedure `f`

 

Warning, `rate` is implicitly declared local to procedure `f`

 

Warning, `mu1` is implicitly declared local to procedure `f`

 

Warning, `mu2` is implicitly declared local to procedure `f`

 

Warning, `mu3` is implicitly declared local to procedure `f`

 

Warning, `p` is implicitly declared local to procedure `f`

 

Warning, `j` is implicitly declared local to procedure `f`

 

Warning, `SumOfAllProb` is implicitly declared local to procedure `f`

 

Warning, `piplus0` is implicitly declared local to procedure `f`

 

Warning, `TotalPower` is implicitly declared local to procedure `f`

 

Warning, `MeanSysLength` is implicitly declared local to procedure `f`

 

Warning, `lambda` is implicitly declared local to procedure `f`

 

Warning, `Ave_Ene` is implicitly declared local to procedure `f`

 

Warning, `MeanWait` is implicitly declared local to procedure `f`

 

proc (x1, x2)::float; local a1temp, a2temp, a3temp, i, a1, a2, a3, a1bartemp, a2bartemp, a3bartemp, a1bar, a2bar, a3bar, L1, L2, L3, power1, power2, power3, power4, rate, mu1, mu2, mu3, p, j, SumOfAllProb, piplus0, TotalPower, MeanSysLength, lambda, Ave_Ene, MeanWait; a1temp := readdata("a1.txt", float); a2temp := readdata("a2.txt", float); a3temp := readdata("a3.txt", float); for i from 0 to ArrayTools:-Size(a1temp, 2)-1 do a1[i] := a1temp[i+1]; a2[i] := a2temp[i+1]; a3[i] := a3temp[i+1] end do; a1bartemp := readdata("a1bar.txt", float); a2bartemp := readdata("a2bar.txt", float); a3bartemp := readdata("a3bar.txt", float); for i from 0 to ArrayTools:-Size(a1bartemp, 2)-1 do a1bar[i] := a1bartemp[i+1]; a2bar[i] := a2bartemp[i+1]; a3bar[i] := a3bartemp[i+1] end do; L1 := x1; L2 := x2; L3 := 50; power1 := 10000000; power2 := 150000000; power3 := 200000000; power4 := 45; unassign('KConst'); unassign('p'); unassign('TotalPower'); rate := readdata("servrate.txt", float); mu1 := rate[1]; mu2 := rate[2]; mu3 := rate[3]; for i from 0 to L3+1 do p[i] := 0 end do; p[0] := KConst; p[1] := p[0]*(1-a1[0])/a1[0]; for j to L1-1 do p[j+1] := (p[j]-p[0]*a1[j]-add(p[i]*a1[j-i+1], i = 1 .. j))/a1[0] end do; for j from L1 to L2-1 do p[j+1] := (p[j]-p[0]*a1[j]-add(p[i]*a1[j-i+1], i = 1 .. L1)-add(p[i]*a2[j-i+1], i = L1+1 .. j))/a2[0] end do; for j from L2 to L3-1 do p[j+1] := (p[j]-p[0]*a1[j]-add(p[i]*a1[j-i+1], i = 1 .. L1)-add(p[i]*a2[j-i+1], i = L1+1 .. L2)-add(p[i]*a3[j-i+1], i = L2+1 .. j))/a3[0] end do; p[L3+1] := (p[0]*a1bar[L3+1]+add(p[i]*a1bar[L3-i+2], i = 1 .. L1)+add(p[i]*a2bar[L3-i+2], i = L1+1 .. L2)+add(p[i]*a3bar[L3-i+2], i = L2+1 .. L3))/(1-a3bar[1]); SumOfAllProb := add(p[i], i = 0 .. L3+1); piplus0 := fsolve(SumOfAllProb = 1, KConst); p[0] := piplus0; p[1] := p[0]*(1-a1[0])/a1[0]; for j to L1-1 do p[j+1] := (p[j]-p[0]*a1[j]-add(p[i]*a1[j-i+1], i = 1 .. j))/a1[0] end do; for j from L1 to L2-1 do p[j+1] := (p[j]-p[0]*a1[j]-add(p[i]*a1[j-i+1], i = 1 .. L1)-add(p[i]*a2[j-i+1], i = L1+1 .. j))/a2[0] end do; for j from L2 to L3-1 do p[j+1] := (p[j]-p[0]*a1[j]-add(p[i]*a1[j-i+1], i = 1 .. L1)-add(p[i]*a2[j-i+1], i = L1+1 .. L2)-add(p[i]*a3[j-i+1], i = L2+1 .. j))/a3[0] end do; p[L3+1] := (p[0]*a1bar[L3+1]+add(p[i]*a1bar[L3-i+2], i = 1 .. L1)+add(p[i]*a2bar[L3-i+2], i = L1+1 .. L2)+add(p[i]*a3bar[L3-i+2], i = L2+1 .. L3))/(1-a3bar[1]); TotalPower := power1*add(p[i], i = 1 .. L1-1)+power2*add(p[i], i = L1 .. L2-1)+power3*add(p[i], i = L2 .. L3-1); MeanSysLength := add(i*p[i], i = 0 .. L3+1); lambda := 125; if 0 <= MeanSysLength and MeanSysLength <= L1 then Ave_Ene := power1 end if; if L1 < MeanSysLength and MeanSysLength <= L2 then Ave_Ene := power2 end if; if L2 < MeanSysLength and MeanSysLength <= 50 then Ave_Ene := power3 end if; MeanWait := MeanSysLength/(lambda*(1-p[L3+1])); return Ave_Ene, MeanWait end proc

(3)

NULL

NULL

``

NULL

NULL

f1 := proc (n) local x, y, i, rx, ry, dumbindex; dumbindex := 1; xdumb[1] := n; ydumb[1] := n; for i to n do d := .12; flag := 1; while .1 < d or flag = 1 do rx := rand(1 .. n); x[i] := rx(); ry := rand(x[i] .. n); y[i] := ry(); flag := check(x[i], y[i], xdumb, ydumb, dumbindex); if flag = 1 then dumbindex := dumbindex+1; xdumb[dumbindex] := x[i]; ydumb[dumbindex] := y[i] end if; p, d := f(x[i], y[i]) end do; xl[i] := x[i]; yl[i] := y[i]; if i = 1 then temp := p; xg := x[i]; yg := y[i] else if p < temp then temp := p; xg := x[i]; yg := y[i] end if end if; vx := rand(-n .. n); vx[i] := vx(); vy := rand(-n .. n); vy[i] := vy() end do; count := 1; while count < 100 do count := count+1; w := .9-((1/100)*.9+(1/100)*(-.4))*(count-1); for i to n do a := rand(0 .. 1); rp := a(); rd := a(); vx[i] := w*vx[i]+2*rp*[xl[i]-x[i]]+2*rd*[xg-x[i]]; x[i] := x[i]+vx[i]; vy[i] := w*vy[i]+2*rp*[yl[i]-y[i]]+2*rd*[yg-y[i]]; y[i] := y[i]+vy[i]; if x[i] < 0 or y[i] < 0 or 50 < x[i] or 50 < y[i] or y[i] < x[i] then p := 1000000000000; if x[i] < 0 or 50 < x[i] then vx[i] := -a()*vx[i] end if; if y[i] < 0 or 50 < y[i] then vy[i] := -a()*vy[i] end if else p, d := f(x[i], y[i]); if .1 < d then p := 100000000000 end if end if; pl, dl := f(xl[i], yl[i]); if p < pl then xl[i] := x[i]; yl[i] := y[i] end if; pg, dg := f(xg, yg); if p < pg then xg := x[i]; yg := y[i] end if end do end do; return xg, yg end proc;

Warning, `xdumb` is implicitly declared local to procedure `f1`

 

Warning, `ydumb` is implicitly declared local to procedure `f1`

 

Warning, `d` is implicitly declared local to procedure `f1`

 

Warning, `flag` is implicitly declared local to procedure `f1`

 

Warning, `p` is implicitly declared local to procedure `f1`

 

Warning, `xl` is implicitly declared local to procedure `f1`

 

Warning, `yl` is implicitly declared local to procedure `f1`

 

Warning, `temp` is implicitly declared local to procedure `f1`

 

Warning, `xg` is implicitly declared local to procedure `f1`

 

Warning, `yg` is implicitly declared local to procedure `f1`

 

Warning, `vx` is implicitly declared local to procedure `f1`

 

Warning, `vy` is implicitly declared local to procedure `f1`

 

Warning, `count` is implicitly declared local to procedure `f1`

 

Warning, `w` is implicitly declared local to procedure `f1`

 

Warning, `a` is implicitly declared local to procedure `f1`

 

Warning, `rp` is implicitly declared local to procedure `f1`

 

Warning, `rd` is implicitly declared local to procedure `f1`

 

Warning, `pl` is implicitly declared local to procedure `f1`

 

Warning, `dl` is implicitly declared local to procedure `f1`

 

Warning, `pg` is implicitly declared local to procedure `f1`

 

Warning, `dg` is implicitly declared local to procedure `f1`

 

proc (n) local x, y, i, rx, ry, dumbindex, xdumb, ydumb, d, flag, p, xl, yl, temp, xg, yg, vx, vy, count, w, a, rp, rd, pl, dl, pg, dg; dumbindex := 1; xdumb[1] := n; ydumb[1] := n; for i to n do d := .12; flag := 1; while .1 < d or flag = 1 do rx := rand(1 .. n); x[i] := rx(); ry := rand(x[i] .. n); y[i] := ry(); flag := check(x[i], y[i], xdumb, ydumb, dumbindex); if flag = 1 then dumbindex := dumbindex+1; xdumb[dumbindex] := x[i]; ydumb[dumbindex] := y[i] end if; p, d := f(x[i], y[i]) end do; xl[i] := x[i]; yl[i] := y[i]; if i = 1 then temp := p; xg := x[i]; yg := y[i] else if p < temp then temp := p; xg := x[i]; yg := y[i] end if end if; vx := rand(-n .. n); vx[i] := vx(); vy := rand(-n .. n); vy[i] := vy() end do; count := 1; while count < 100 do count := count+1; w := .9-((1/100)*.9+(-1/100)*.4)*(count-1); for i to n do a := rand(0 .. 1); rp := a(); rd := a(); vx[i] := w*vx[i]+2*rp*[xl[i]-x[i]]+2*rd*[xg-x[i]]; x[i] := x[i]+vx[i]; vy[i] := w*vy[i]+2*rp*[yl[i]-y[i]]+2*rd*[yg-y[i]]; y[i] := y[i]+vy[i]; if x[i] < 0 or y[i] < 0 or 50 < x[i] or 50 < y[i] or y[i] < x[i] then p := 1000000000000; if x[i] < 0 or 50 < x[i] then vx[i] := -a()*vx[i] end if; if y[i] < 0 or 50 < y[i] then vy[i] := -a()*vy[i] end if else p, d := f(x[i], y[i]); if .1 < d then p := 100000000000 end if end if; pl, dl := f(xl[i], yl[i]); if p < pl then xl[i] := x[i]; yl[i] := y[i] end if; pg, dg := f(xg, yg); if p < pg then xg := x[i]; yg := y[i] end if end do end do; return xg, yg end proc

(4)

check := proc (a, b, c, d, index) flag := 1; for i to index do if a = c[i] then flag := 0; break else for j to index do if b = d[i] then flag := 0; break end if end do end if end do; return flag end proc;

Warning, `flag` is implicitly declared local to procedure `check`

 

Warning, `i` is implicitly declared local to procedure `check`

 

Warning, `j` is implicitly declared local to procedure `check`

 

proc (a, b, c, d, index) local flag, i, j; flag := 1; for i to index do if a = c[i] then flag := 0; break else for j to index do if b = d[i] then flag := 0; break end if end do end if end do; return flag end proc

(5)

NULL

NULL

f(20, 30)

150000000, .1864486160608827083274069133103083161519725756874613823622460642428317572211670199879099898028956205

(6)

f(50, 50)

10000000, .3676962595297939383646215059959106211661626284844402961967786676403484124931253985361996885223199928

(7)

f(1, 1)

200000000, 0.4316184642195966203873793077122502318769559506633094004563902218673440393334833004536028696659255751e-1

(8)

currentdir("/Users/min/Dropbox/Durham/Dib-Thresholded_Queue")

"/Users/min/Dropbox/Durham/Dib-Thresholded_Queue"

(9)

currentdir()

"/Users/min/Dropbox/Durham/Dib-Thresholded_Queue"

(10)

s

s

(11)

f1(50)

Error, (in f1) too many levels of recursion

 

``


 

Download Untitled_JIE.mw

 

@Rouben Rostamian  Thank you. You saved me day...By the way, do you know how to turn on the debugging button on the window frame. It is being inactive status and I can not debug my codes.

Page 1 of 1