Exemple #1
0
// PlotFltOva plots flt-ova points
func (o *Optimiser) PlotFltOva(sols0 []*Solution, iFlt, iOva int, ovaMult float64, pp *PlotParams) {
	if pp.YfuncX != nil {
		X := utl.LinSpace(o.FltMin[iFlt], o.FltMax[iFlt], pp.NptsYfX)
		Y := make([]float64, pp.NptsYfX)
		for i := 0; i < pp.NptsYfX; i++ {
			Y[i] = pp.YfuncX(X[i])
		}
		plt.Plot(X, Y, pp.FmtYfX.GetArgs(""))
	}
	if sols0 != nil {
		o.PlotAddFltOva(iFlt, iOva, sols0, ovaMult, &pp.FmtSols0)
	}
	o.PlotAddFltOva(iFlt, iOva, o.Solutions, ovaMult, &pp.FmtSols)
	best, _ := GetBestFeasible(o, iOva)
	if best != nil {
		plt.PlotOne(best.Flt[iFlt], best.Ova[iOva]*ovaMult, pp.FmtBest.GetArgs(""))
	}
	if pp.Extra != nil {
		pp.Extra()
	}
	if pp.AxEqual {
		plt.Equal()
	}
	plt.Gll(io.Sf("$x_{%d}$", iFlt), io.Sf("$f_{%d}$", iOva), "leg_out=1, leg_ncol=4, leg_hlen=1.5")
	plt.SaveD(pp.DirOut, pp.FnKey+pp.FnExt)
}
Exemple #2
0
func (o *Plotter) Plot_Dgam_f(x, y []float64, res []*State, sts [][]float64, last bool) {
	if o.m == nil {
		o.set_empty()
		return
	}
	nr := len(res)
	k := nr - 1
	ys := o.m.YieldFuncs(res[0])
	fc0 := ys[0]
	xmi, xma, ymi, yma := res[0].Dgam, res[0].Dgam, fc0, fc0
	for i := 0; i < nr; i++ {
		x[i] = res[i].Dgam
		ys = o.m.YieldFuncs(res[i])
		y[i] = ys[0]
		xmi = min(xmi, x[i])
		xma = max(xma, x[i])
		ymi = min(ymi, y[i])
		yma = max(yma, y[i])
	}
	//o.DrawRamp(xmi, xma, ymi, yma)
	plt.Plot(x, y, io.Sf("'r.', ls='%s', clip_on=0, color='%s', marker='%s', label=r'%s'", o.Ls, o.Clr, o.Mrk, o.Lbl))
	plt.PlotOne(x[0], y[0], io.Sf("'bo', clip_on=0, color='%s', marker='%s', ms=%d", o.SpClr, o.SpMrk, o.SpMs))
	plt.PlotOne(x[k], y[k], io.Sf("'bs', clip_on=0, color='%s', marker='%s', ms=%d", o.SpClr, o.EpMrk, o.EpMs))
	if last {
		plt.Gll("$\\Delta\\gamma$", "$f$", "")
		if lims, ok := o.Lims["Dgam,f"]; ok {
			plt.AxisLims(lims)
		}
	}
}
Exemple #3
0
func Camera(elev, azim float64, args string) {
	cmd := io.Sf("gca().view_init(elev=%g, azim=%g", elev, azim)
	if len(args) > 0 {
		cmd += io.Sf(",%s", args)
	}
	io.Ff(&bb, "%s)\n", cmd)
}
Exemple #4
0
func Arrow(xi, yi, xf, yf float64, args string) {
	cmd := io.Sf("Arrow(%g,%g, %g,%g", xi, yi, xf, yf)
	if len(args) > 0 {
		cmd += io.Sf(",%s", args)
	}
	io.Ff(&bb, "%s)\n", cmd)
}
Exemple #5
0
// String prints a json formatted string with GeoLayers' content
func (o GeoLayers) String() string {
	if len(o) == 0 {
		return "[]"
	}
	l := "[\n"
	for i, lay := range o {
		if i > 0 {
			l += ",\n"
		}
		l += io.Sf("  { \"Tags\":%v, \"Zmin\":%g, \"Zmax\":%g, \"nf0\":%g, \"RhoS0\":%g, \"Cl\":%g\n", lay.Tags, lay.Zmin, lay.Zmax, lay.nf0, lay.RhoS0, lay.Cl)
		l += "    \"Nodes\":["
		for j, nod := range lay.Nodes {
			if j > 0 {
				l += ","
			}
			l += io.Sf("%d", nod.Vert.Id)
		}
		l += "],\n    \"Elems\":["
		for j, ele := range lay.Elems {
			if j > 0 {
				l += ","
			}
			l += io.Sf("%d", ele.Id())
		}
		l += "] }"
	}
	l += "\n]"
	return l
}
Exemple #6
0
func Circle(xc, yc, r float64, args string) {
	cmd := io.Sf("Circle(%g,%g,%g", xc, yc, r)
	if len(args) > 0 {
		cmd += io.Sf(",%s", args)
	}
	io.Ff(&bb, "%s)\n", cmd)
}
Exemple #7
0
// Plot plots retention model
//  args1 -- arguments for model computed by solving differential equation; e.g. "'b*-'"
//           if args1 == "", plot is skiped
//  args2 -- arguments for model computed by directly calling sl(pc), if available
//           if args2 == "", plot is skiped
func Plot(mdl Model, pc0, sl0, pcf float64, npts int, args1, args2, label string) (err error) {

	// plot using Update
	Pc := utl.LinSpace(pc0, pcf, npts)
	Sl := make([]float64, npts)
	if args1 != "" {
		Sl[0] = sl0
		for i := 1; i < npts; i++ {
			Sl[i], err = Update(mdl, Pc[i-1], Sl[i-1], Pc[i]-Pc[i-1])
			if err != nil {
				return
			}
		}
		plt.Plot(Pc, Sl, io.Sf("%s, label='%s', clip_on=0", args1, label))
	}

	// plot using Sl function
	if args2 != "" {
		if m, ok := mdl.(Nonrate); ok {
			Pc = utl.LinSpace(pc0, pcf, 101)
			Sl = make([]float64, 101)
			for i, pc := range Pc {
				Sl[i] = m.Sl(pc)
			}
			plt.Plot(Pc, Sl, io.Sf("%s, label='%s_direct', clip_on=0", args2, label))
		}
	}
	return
}
Exemple #8
0
// StrDistMatrix returns a string representation of Dist matrix
func (o *Graph) StrDistMatrix() (l string) {
	nv := len(o.Dist)
	maxlen := 0
	for i := 0; i < nv; i++ {
		for j := 0; j < nv; j++ {
			if o.Dist[i][j] < GRAPH_INF {
				maxlen = utl.Imax(maxlen, len(io.Sf("%g", o.Dist[i][j])))
			}
		}
	}
	maxlen = utl.Imax(3, maxlen)
	fmts := io.Sf("%%%ds", maxlen+1)
	fmtn := io.Sf("%%%dg", maxlen+1)
	for i := 0; i < nv; i++ {
		for j := 0; j < nv; j++ {
			if o.Dist[i][j] < GRAPH_INF {
				l += io.Sf(fmtn, o.Dist[i][j])
			} else {
				l += io.Sf(fmts, "∞")
			}
		}
		l += "\n"
	}
	return
}
Exemple #9
0
func Annotate(x, y float64, txt string, args string) {
	cmd := io.Sf("annotate(%s, xy=(%g,%g)", txt, x, y)
	if len(args) > 0 {
		cmd += io.Sf(",%s", args)
	}
	io.Ff(&bb, "%s)\n", cmd)
}
Exemple #10
0
// CheckDerivT checks derivatives w.r.t to t for fixed coordinates x
func CheckDerivT(tst *testing.T, o Func, t0, tf float64, xcte []float64, np int, tskip []float64, sktol, dtol, dtol2 float64, ver bool) {
	t := utl.LinSpace(t0, tf, np)
	for i := 0; i < np; i++ {
		g := o.G(t[i], xcte)
		h := o.H(t[i], xcte)
		skip := false
		for _, val := range tskip {
			if math.Abs(val-t[i]) < sktol {
				skip = true
				break
			}
		}
		if skip {
			continue
		}
		dnum := num.DerivCen(func(t float64, args ...interface{}) (res float64) {
			return o.F(t, xcte)
		}, t[i])
		chk.AnaNum(tst, io.Sf("G(%10f)", t[i]), dtol, g, dnum, ver)
		dnum2 := num.DerivCen(func(t float64, args ...interface{}) (res float64) {
			return o.G(t, xcte)
		}, t[i])
		chk.AnaNum(tst, io.Sf("H(%10f)", t[i]), dtol2, h, dnum2, ver)
	}
}
Exemple #11
0
func (o FemData) Info() (l string) {
	l += io.Sf("VtagU  = %v\n", o.VtagU)
	l += io.Sf("AwdU   = %v\n", o.AwdU)
	l += io.Sf("AwdM22 = %v\n", o.AwdM22)
	l += io.Sf("AwdM11 = %v\n", o.AwdM11)
	return
}
Exemple #12
0
func (o *Plotter) Plot_ed_q(x, y []float64, res []*State, sts [][]float64, last bool) {
	nr := len(res)
	if len(sts) != nr {
		return
	}
	k := nr - 1
	for i := 0; i < nr; i++ {
		x[i] = o.Ed[i] * 100.0
		if o.QdivP {
			y[i] = o.Q[i] / o.P[i]
		} else {
			y[i] = o.Q[i]
		}
		if o.Multq {
			y[i] *= fun.Sign(o.W[i])
		}
	}
	plt.Plot(x, y, io.Sf("'r.', ls='%s', clip_on=0, color='%s', marker='%s', label=r'%s'", o.Ls, o.Clr, o.Mrk, o.Lbl))
	plt.PlotOne(x[0], y[0], io.Sf("'bo', clip_on=0, color='%s', marker='%s', ms=%d", o.SpClr, o.SpMrk, o.SpMs))
	plt.PlotOne(x[k], y[k], io.Sf("'bs', clip_on=0, color='%s', marker='%s', ms=%d", o.SpClr, o.EpMrk, o.EpMs))
	if last {
		ylbl := "$q$"
		if o.QdivP {
			ylbl = "$q/p$"
		}
		plt.Gll("$\\varepsilon_d\\;[\\%]$", ylbl, "leg_out=1, leg_ncol=4, leg_hlen=1.5")
		if lims, ok := o.Lims["ed,q"]; ok {
			plt.AxisLims(lims)
		}
	}
}
Exemple #13
0
func (o *Plotter) Plot_i_f(x, y []float64, res []*State, sts [][]float64, last bool) {
	if o.m == nil {
		o.set_empty()
		return
	}
	nr := len(res)
	var y2 []float64
	if o.nsurf > 1 {
		y2 = make([]float64, nr)
	}
	for i := 0; i < nr; i++ {
		ys := o.m.YieldFuncs(res[i])
		y[i] = ys[0]
		if o.nsurf > 1 {
			y2[i] = ys[1]
		}
		x[i] = float64(i)
	}
	lbl := "f " + o.Lbl
	plt.Plot(x, y, io.Sf("'r.', ls='-', clip_on=0, color='%s', marker='%s', label=r'%s'", o.Clr, o.Mrk, lbl))
	if o.nsurf > 1 {
		lbl = "F " + o.Lbl
		plt.Plot(x, y2, io.Sf("'b+', ls=':', lw=2, clip_on=0, color='%s', marker='%s', label=r'%s'", o.Clr, o.Mrk, lbl))
	}
	if last {
		plt.Gll("$i$", "$f,\\;F$", "leg_out=1, leg_ncol=4, leg_hlen=2")
		if lims, ok := o.Lims["i,f"]; ok {
			plt.AxisLims(lims)
		}
	}
}
Exemple #14
0
// PlotAll plot all functions
func (o FuncsData) PlotAll(pd *PlotFdata, dirout, fnkey string) {
	ext := "png"
	if pd.Eps {
		ext = "eps"
	}
	fn := io.Sf("functions-%s.%s", fnkey, ext)
	plt.Reset()
	for k, f := range o {
		if utl.StrIndexSmall(pd.Skip, f.Name) >= 0 {
			continue
		}
		save := (k == len(o)-1)
		args := io.Sf("label='%s', clip_on=0", f.Name)
		ff := o.Get(f.Name)
		if ff != nil {
			if pd.WithTxt {
				x := pd.Ti
				y := ff.F(x, nil)
				plt.Text(x, y, io.Sf("%g", y), "fontsize=8")
				x = pd.Tf
				y = ff.F(x, nil)
				plt.Text(x, y, io.Sf("%g", y), "fontsize=8, ha='right'")
			}
			fun.PlotT(ff, dirout, fn, pd.Ti, pd.Tf, nil, pd.Np, args, pd.WithG, pd.WithH, save, false, nil)
		}
	}
}
Exemple #15
0
func checkinput(tst *testing.T, m *Mesh, nverts, ncells int, X [][]float64, vtags, ctags, parts []int, types []string, V [][]int, etags, ftags [][]int) {
	if len(m.Verts) != nverts {
		tst.Errorf("nverts is incorrect: %d != %d", len(m.Verts), nverts)
		return
	}
	if len(m.Cells) != ncells {
		tst.Errorf("ncells is incorrect: %d != %d", len(m.Cells), ncells)
		return
	}
	io.Pfyel("\nvertices:\n")
	for i, v := range m.Verts {
		io.Pf("%+v\n", v)
		chk.Vector(tst, io.Sf("vertex %2d: X", v.Id), 1e-15, v.X, X[v.Id])
		if v.Tag != vtags[i] {
			tst.Errorf("vtag is incorrect: %d != %d", v.Tag, vtags[i])
			return
		}
	}
	io.Pfyel("\ncells:\n")
	for i, c := range m.Cells {
		io.Pf("%+v\n", c)
		if c.Tag != ctags[i] {
			tst.Errorf("ctag is incorrect: %d != %d", c.Tag, ctags[i])
			return
		}
		if c.Part != parts[i] {
			tst.Errorf("part is incorrect: %d != %d", c.Part, parts[i])
			return
		}
		chk.String(tst, types[i], c.Type)
		chk.Ints(tst, io.Sf("cell %2d : V", c.Id), c.V, V[c.Id])
		chk.Ints(tst, io.Sf("cell %2d : edgetags", c.Id), c.EdgeTags, etags[c.Id])
	}
}
Exemple #16
0
// PlotDerivs plots derivatives of basis functions in I
// option =  0 : use CalcBasisAndDerivs
//           1 : use NumericalDeriv
func (o *Bspline) PlotDerivs(args string, npts, option int) {
	nmks := 10
	tt := utl.LinSpace(o.tmin, o.tmax, npts)
	I := utl.IntRange(o.NumBasis())
	f := make([]float64, len(tt))
	lbls := []string{"N\\&dN", "numD"}
	var cmd string
	for _, i := range I {
		for j, t := range tt {
			switch option {
			case 0:
				o.CalcBasisAndDerivs(t)
				f[j] = o.GetDeriv(i)
			case 1:
				f[j] = o.NumericalDeriv(t, i)
			}
		}
		if strings.Contains(args, "marker") {
			cmd = io.Sf("label=r'%s:%d', color=GetClr(%d, 2) %s", lbls[option], i, i, args)
		} else {
			cmd = io.Sf("label=r'%s:%d', marker=(None if %d %%2 == 0 else GetMrk(%d/2,1)), markevery=(%d-1)/%d, clip_on=0, color=GetClr(%d, 2) %s", lbls[option], i, i, i, npts, nmks, i, args)
		}
		plt.Plot(tt, f, cmd)
	}
	plt.Gll("$t$", io.Sf(`$\frac{\mathrm{d}N_{i,%d}}{\mathrm{d}t}$`, o.p), io.Sf("leg=1, leg_out=1, leg_ncol=%d, leg_hlen=1.5, leg_fsz=7", o.NumBasis()))
	o.plt_ticks_spans()
}
Exemple #17
0
func (o *Plotter) Plot_i_alp(x, y []float64, res []*State, sts [][]float64, last bool) {
	nr := len(res)
	nα := len(res[0].Alp)
	if nα == 0 {
		o.set_empty()
		return
	}
	yy := la.MatAlloc(nα, nr)
	for i := 0; i < nr; i++ {
		x[i] = float64(i)
		for j := 0; j < nα; j++ {
			yy[j][i] = res[i].Alp[j]
		}
	}
	for j := 0; j < nα; j++ {
		lbl := io.Sf("$\\alpha_%d$ "+o.Lbl, j)
		plt.Plot(x, yy[j], io.Sf("'r-', ls='-', clip_on=0, color='%s', marker='%s', label=r'%s'", o.Clr, o.Mrk, lbl))
	}
	if last {
		plt.Gll("$i$", "$\\alpha_k$", "leg_out=1, leg_ncol=4, leg_hlen=2")
		if lims, ok := o.Lims["i,alp"]; ok {
			plt.AxisLims(lims)
		}
	}
}
Exemple #18
0
func AxHline(y float64, args string) {
	cmd := io.Sf("axhline(%g", y)
	if len(args) > 0 {
		cmd += io.Sf(",%s", args)
	}
	io.Ff(&bb, "%s)\n", cmd)
}
Exemple #19
0
// String returns a JSON representation of *Cell
func (o *Cell) String() string {
	l := io.Sf("{\"i\":%d, \"t\":%d, \"p\":%d, \"y\":%q, \"v\":[", o.Id, o.Tag, o.Part, o.Type)
	for i, x := range o.V {
		if i > 0 {
			l += ", "
		}
		l += io.Sf("%d", x)
	}
	if len(o.EdgeTags) > 0 {
		l += "], \"et\":["
		for i, x := range o.EdgeTags {
			if i > 0 {
				l += ", "
			}
			l += io.Sf("%d", x)
		}
	}
	if len(o.FaceTags) > 0 {
		l += "], \"ft\":["
		for i, x := range o.FaceTags {
			if i > 0 {
				l += ", "
			}
			l += io.Sf("%d", x)
		}
	}
	l += "] }"
	return l
}
Exemple #20
0
func AxVline(x float64, args string) {
	cmd := io.Sf("axvline(%g", x)
	if len(args) > 0 {
		cmd += io.Sf(",%s", args)
	}
	io.Ff(&bb, "%s)\n", cmd)
}
Exemple #21
0
func WriteAllValues(dirout, fnkey string, opt *Optimiser) {
	var buf bytes.Buffer
	io.Ff(&buf, "%5s", "front")
	for i := 0; i < opt.Nova; i++ {
		io.Ff(&buf, "%24s", io.Sf("f%d", i))
	}
	for i := 0; i < opt.Noor; i++ {
		io.Ff(&buf, "%24s", io.Sf("u%d", i))
	}
	for i := 0; i < opt.Nflt; i++ {
		io.Ff(&buf, "%24s", io.Sf("x%d", i))
	}
	for i := 0; i < opt.Nint; i++ {
		io.Ff(&buf, "%24s", io.Sf("y%d", i))
	}
	io.Ff(&buf, "\n")
	for _, sol := range opt.Solutions {
		io.Ff(&buf, "%5d", sol.FrontId)
		for i := 0; i < opt.Nova; i++ {
			io.Ff(&buf, "%24g", sol.Ova[i])
		}
		for i := 0; i < opt.Noor; i++ {
			io.Ff(&buf, "%24g", sol.Oor[i])
		}
		for i := 0; i < opt.Nflt; i++ {
			io.Ff(&buf, "%24g", sol.Flt[i])
		}
		for i := 0; i < opt.Nint; i++ {
			io.Ff(&buf, "%24g", sol.Int[i])
		}
		io.Ff(&buf, "\n")
	}
	io.WriteFileVD(dirout, fnkey+".res", &buf)
}
Exemple #22
0
func AnnotateXlabels(x float64, txt string, args string) {
	cmd := io.Sf("AnnotateXlabels(%g, %s", x, txt)
	if len(args) > 0 {
		cmd += io.Sf(",%s", args)
	}
	io.Ff(&bb, "%s)\n", cmd)
}
Exemple #23
0
func Gll(xl, yl string, args string) {
	n := bb.Len()
	cmd := io.Sf("lg%d = Gll(r'%s',r'%s'", n, xl, yl)
	if len(args) > 0 {
		cmd += io.Sf(",%s", args)
	}
	io.Ff(&bb, "%s)\nea.append(lg%d)\n", cmd, n)
}
Exemple #24
0
func UnitFormat(unit string) (tex string) {
	if strings.Contains(unit, "m3") {
		return io.Sf("$\\mathrm{%s}$", strings.Replace(unit, "m3", "m^3", -1))
	}
	if strings.Contains(unit, "m2") {
		return io.Sf("$\\mathrm{%s}$", strings.Replace(unit, "m2", "m^2", -1))
	}
	return unit
}
Exemple #25
0
func Test_igd01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("igd. igd metric with star equal to trial => igd=0")

	// load star values
	prob := "UF1"
	fStar, err := io.ReadMatrix(io.Sf("./examples/mulobj-cec09/cec09/pf_data/%s.dat", prob))
	if err != nil {
		tst.Errorf("cannot read fStar matrix:\n%v", err)
		return
	}
	npts := len(fStar)

	// optimiser
	var opt Optimiser
	opt.Default()
	opt.Nsol = npts
	opt.Ncpu = 1
	opt.FltMin = []float64{0, 0} // used to store fStar
	opt.FltMax = []float64{1, 1} // used to store fStar
	nf, ng, nh := 2, 0, 0

	// generator (store fStar into Flt)
	gen := func(sols []*Solution, prms *Parameters) {
		for i, sol := range sols {
			sol.Flt[0], sol.Flt[1] = fStar[i][0], fStar[i][1]
		}
	}

	// objective function (copy fStar from Flt into Ova)
	obj := func(f, g, h, x []float64, ξ []int, cpu int) {
		f[0], f[1] = x[0], x[1]
	}

	// initialise optimiser
	opt.Init(gen, nil, obj, nf, ng, nh)

	// compute igd
	igd := StatIgd(&opt, fStar)
	io.Pforan("igd = %v\n", igd)
	chk.Scalar(tst, "igd", 1e-15, igd, 0)

	// plot
	if chk.Verbose {
		fmt := &plt.Fmt{C: "red", M: ".", Ms: 1, Ls: "None", L: "solutions"}
		fS0 := utl.DblsGetColumn(0, fStar)
		fS1 := utl.DblsGetColumn(1, fStar)
		io.Pforan("len(fS0) = %v\n", len(fS0))
		plt.SetForEps(0.75, 300)
		opt.PlotAddOvaOva(0, 1, opt.Solutions, true, fmt)
		plt.Plot(fS0, fS1, io.Sf("'b.', ms=2, label='star(%s)', clip_on=0", prob))
		plt.Gll("$f_0$", "$f_1$", "")
		plt.SaveD("/tmp/goga", "igd01.eps")
	}
}
Exemple #26
0
// PlotBasis plots basis function (2D only)
// option =  0 : use CalcBasis
//           1 : use CalcBasisAndDerivs
//           2 : use RecursiveBasis
func (o *Nurbs) PlotBasis(l int, args string, npts, option int) {
	lbls := []string{"CalcBasis function", "CalcBasisAndDerivs function", "RecursiveBasis function"}
	switch o.gnd {
	// curve
	case 1:
		U := make([]float64, npts)
		S := make([]float64, npts)
		du := (o.b[0].tmax - o.b[0].tmin) / float64(npts-1)
		uvec := []float64{0}
		for m := 0; m < npts; m++ {
			U[m] = o.b[0].tmin + float64(m)*du
			uvec[0] = U[m]
			switch option {
			case 0:
				o.CalcBasis(uvec)
				S[m] = o.GetBasisL(l)
			case 1:
				o.CalcBasisAndDerivs(uvec)
				S[m] = o.GetBasisL(l)
			case 2:
				S[m] = o.RecursiveBasis(uvec, l)
			}
		}
		plt.Plot(U, S, args)
		plt.Gll("$u$", io.Sf("$S_%d$", l), "")
	// surface
	case 2:
		xx := la.MatAlloc(npts, npts)
		yy := la.MatAlloc(npts, npts)
		zz := la.MatAlloc(npts, npts)
		du0 := (o.b[0].tmax - o.b[0].tmin) / float64(npts-1)
		du1 := (o.b[1].tmax - o.b[1].tmin) / float64(npts-1)
		for m := 0; m < npts; m++ {
			u0 := o.b[0].tmin + float64(m)*du0
			for n := 0; n < npts; n++ {
				u1 := o.b[1].tmin + float64(n)*du1
				u := []float64{u0, u1}
				x := o.Point(u)
				xx[m][n] = x[0]
				yy[m][n] = x[1]
				switch option {
				case 0:
					o.CalcBasis(u)
					zz[m][n] = o.GetBasisL(l)
				case 1:
					o.CalcBasisAndDerivs(u)
					zz[m][n] = o.GetBasisL(l)
				case 2:
					zz[m][n] = o.RecursiveBasis(u, l)
				}
			}
		}
		plt.Contour(xx, yy, zz, "fsz=7")
	}
	plt.Title(io.Sf("%s @ %d", lbls[option], l), "size=7")
}
Exemple #27
0
// DrawCtrl2d draws control net
func (o *Nurbs) DrawCtrl2d(ids bool, args, idargs string) {
	if len(idargs) == 0 {
		idargs = "color='r', size=7"
	}
	switch o.gnd {
	// curve
	case 1:
		xa := make([]float64, o.n[0])
		ya := make([]float64, o.n[0])
		j, k := 0, 0
		for i := 0; i < o.n[0]; i++ {
			xa[i] = o.Q[i][j][k][0] / o.Q[i][j][k][3]
			ya[i] = o.Q[i][j][k][1] / o.Q[i][j][k][3]
		}
		plt.Plot(xa, ya, "'k.--', clip_on=0"+args)
		if ids {
			for i := 0; i < o.n[0]; i++ {
				x := o.Q[i][j][k][0] / o.Q[i][j][k][3]
				y := o.Q[i][j][k][1] / o.Q[i][j][k][3]
				plt.Text(x, y, io.Sf("%d", i), idargs)
			}
		}
	// surface
	case 2:
		xa := make([]float64, o.n[1])
		ya := make([]float64, o.n[1])
		k := 0
		for i := 0; i < o.n[0]; i++ {
			for j := 0; j < o.n[1]; j++ {
				xa[j] = o.Q[i][j][k][0] / o.Q[i][j][k][3]
				ya[j] = o.Q[i][j][k][1] / o.Q[i][j][k][3]
			}
			plt.Plot(xa, ya, "'k.--', clip_on=0"+args)
		}
		xb := make([]float64, o.n[0])
		yb := make([]float64, o.n[0])
		for j := 0; j < o.n[1]; j++ {
			for i := 0; i < o.n[0]; i++ {
				xb[i] = o.Q[i][j][k][0] / o.Q[i][j][k][3]
				yb[i] = o.Q[i][j][k][1] / o.Q[i][j][k][3]
			}
			plt.Plot(xb, yb, "'k.--', clip_on=0"+args)
		}
		if ids {
			for i := 0; i < o.n[0]; i++ {
				for j := 0; j < o.n[1]; j++ {
					x := o.Q[i][j][k][0] / o.Q[i][j][k][3]
					y := o.Q[i][j][k][1] / o.Q[i][j][k][3]
					l := i + j*o.n[0]
					plt.Text(x, y, io.Sf("%d", l), idargs)
				}
			}
		}
	}
}
Exemple #28
0
// StrCostMatrix returns a representation of cost matrix with masks and covers
func (o *Munkres) StrCostMatrix() (l string) {
	numfmt := "%v"
	l += io.Sf("%4v", " ")
	for j := 0; j < o.ncol; j++ {
		if o.col_covered[j] {
			l += io.Sf("%8v", "T ")
		} else {
			l += io.Sf("%8v", "F ")
		}
	}
	l += io.Sf("\n")
	for i := 0; i < o.nrow; i++ {
		if o.row_covered[i] {
			l += io.Sf("%4v", "T")
		} else {
			l += io.Sf("%4v", "F")
		}
		for j := 0; j < o.ncol; j++ {
			s := io.Sf(numfmt, o.C[i][j])
			switch o.M[i][j] {
			case NONE:
				s += " "
			case STAR:
				s += "*"
			case PRIM:
				s += "'"
			}
			l += io.Sf("%8v", s)
		}
		l += io.Sf("\n")
	}
	return
}
Exemple #29
0
func PrintIndicatorMatrix(x [][]int) (l string) {
	m, n := len(x), len(x[0])
	w := 2*n + 6 + 13
	l = io.Sf("%s i\\j |", io.StrThickLine(w))
	for j := 0; j < n; j++ {
		l += io.Sf("%2d", j)
	}
	l += io.Sf(" |        sum\n%s", io.StrThinLine(w))
	S := make([]int, n)
	for i := 0; i < m; i++ {
		l += io.Sf(" %3d |", i)
		s := 0
		for j := 0; j < n; j++ {
			l += io.Sf("%2d", x[i][j])
			s += x[i][j]
			S[j] += x[i][j]
		}
		l += io.Sf(" | Σ xij = %2d\n", s)
	}
	l += io.Sf("%s sum =", io.StrThinLine(w))
	for j := 0; j < n; j++ {
		l += io.Sf("%2d", S[j])
	}
	l += io.Sf("\n%s", io.StrThickLine(w))
	return
}
Exemple #30
0
func Plot(x, y []float64, args string) {
	n := bb.Len()
	sx := io.Sf("x%d", n)
	sy := io.Sf("y%d", n)
	Gen2Arrays(&bb, sx, sy, x, y)
	if len(args) > 0 {
		io.Ff(&bb, "plot(%s,%s,%s)\n", sx, sy, args)
	} else {
		io.Ff(&bb, "plot(%s,%s)\n", sx, sy)
	}
}