示例#1
0
文件: ReliabFORM.go 项目: cpmech/goga
func main() {

	// input filename
	_, fnkey := io.ArgToFilename(0, "frame2d", ".sim", true)

	// simple problems
	var opts []*goga.Optimiser
	if fnkey == "simple" {
		io.Pf("\n\n\n")
		//P := []int{1}
		P := utl.IntRange2(1, 19)
		opts = make([]*goga.Optimiser, len(P))
		for i, problem := range P {
			opts[i] = solve_problem(fnkey, problem)
		}
	} else {
		opts = []*goga.Optimiser{solve_problem(fnkey, 0)}
	}
	if opts[0].PlotSet1 {
		return
	}

	if opts[0].Nsamples > 1 {
		io.Pf("\n")
		rpt := goga.NewTexReport(opts)
		rpt.ShowDEC = false
		rpt.Type = 4
		rpt.TextSize = ""
		rpt.Title = "FORM Reliability: " + fnkey
		rpt.Fnkey = "rel-" + fnkey
		rpt.Generate()
	}
}
示例#2
0
func Test_intordmut01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("intordmut01")

	var ops OpsData
	ops.SetDefault()
	ops.Pm = 1

	rnd.Init(0)

	a := []int{1, 2, 3, 4, 5, 6, 7, 8}
	io.Pforan("before: a = %v\n", a)
	ops.OrdSti = []int{2, 5, 4}
	IntOrdMutation(a, 0, &ops)
	io.Pfcyan("after:  a = %v\n", a)
	chk.Ints(tst, "a", a, []int{1, 2, 6, 7, 3, 4, 5, 8})
	nums := utl.IntRange2(1, 9)
	sort.Ints(a)
	chk.Ints(tst, "asorted = 12345678", a, nums)

	a = []int{1, 2, 3, 4, 5, 6, 7, 8}
	io.Pforan("\nbefore: a = %v\n", a)
	ops.OrdSti = nil
	IntOrdMutation(a, 0, &ops)
	io.Pfcyan("after:  a = %v\n", a)
	sort.Ints(a)
	chk.Ints(tst, "asorted = 12345678", a, nums)
}
示例#3
0
文件: three-obj.go 项目: cpmech/goga
func main() {
	P := utl.IntRange2(1, 9)
	//P := []int{2}
	opts := make([]*goga.Optimiser, len(P))
	for i, problem := range P {
		opts[i] = solve_problem(problem)
	}
	io.Pf("\n-------------------------- generating report --------------------------\nn")
	rpt := goga.NewTexReport(opts)
	rpt.NRowPerTab = 10
	rpt.Type = 1
	rpt.Title = "Unconstrained and constrained three objective problems."
	rpt.Fnkey = "three-obj"
	rpt.Generate()
}
示例#4
0
文件: ct-two-obj.go 项目: cpmech/goga
func main() {
	textSize := `\scriptsize  \setlength{\tabcolsep}{0.5em}`
	miniPageSz, histTextSize := "4.1cm", `\fontsize{5pt}{6pt}`
	P := utl.IntRange2(0, 9)
	//P := []int{0}
	opts := make([]*goga.Optimiser, len(P))
	for i, problem := range P {
		opts[i] = solve_problem(problem)
	}
	io.Pf("\n-------------------------- generating report --------------------------\nn")
	nRowPerTab := 10
	title := "Constrained two objective problems"
	goga.TexReport("/tmp/goga", "tmp_ct-two-obj", title, "ct-two-obj", 3, nRowPerTab, true, false, textSize, miniPageSz, histTextSize, opts)
	goga.TexReport("/tmp/goga", "ct-two-obj", title, "ct-two-obj", 3, nRowPerTab, false, false, textSize, miniPageSz, histTextSize, opts)
}
示例#5
0
文件: two-obj.go 项目: cpmech/goga
func main() {
	P := utl.IntRange2(1, 7)
	//P := []int{1, 2, 4, 6}
	//P := []int{4, 5, 6}
	//P := []int{4}
	opts := make([]*goga.Optimiser, len(P))
	for i, problem := range P {
		opts[i] = solve_problem(problem)
	}
	io.Pf("\n-------------------------- generating report --------------------------\nn")
	rpt := goga.NewTexReport(opts)
	rpt.NRowPerTab = 9
	rpt.Type = 2
	rpt.Title = "Unconstrained two objective problems."
	rpt.Fnkey = "two-obj"
	rpt.Generate()
}
示例#6
0
文件: random.go 项目: yunpeng1/gosl
// IntGetUniqueN randomly selects n items from start to endp1-1 avoiding duplicates
//  Note: using the 'reservoir sampling' method; see Wikipedia:
//        https://en.wikipedia.org/wiki/Reservoir_sampling
func IntGetUniqueN(start, endp1, n int) (selected []int) {
	if n < 1 {
		return
	}
	size := endp1 - start
	if n >= size {
		selected = utl.IntRange2(start, endp1)
		IntShuffle(selected)
		return
	}
	selected = make([]int, n)
	for i := 0; i < n; i++ {
		selected[i] = start + i
	}
	var j int
	for i := n; i < size; i++ {
		j = rand.Intn(i + 1)
		if j < n {
			selected[j] = start + i
		}
	}
	return
}
示例#7
0
func Test_intordcx01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("intordcx01")

	var ops OpsData
	ops.SetDefault()
	ops.Pc = 1

	rnd.Init(0)

	A := []int{1, 2, 3, 4, 5, 6, 7, 8}
	B := []int{2, 4, 6, 8, 7, 5, 3, 1}
	a := make([]int, len(A))
	b := make([]int, len(A))
	ops.Cuts = []int{2, 5}
	IntOrdCrossover(a, b, A, B, 0, &ops)
	io.Pforan("A = %v\n", A)
	io.Pfblue2("B = %v\n", B)
	io.Pfgreen("a = %v\n", a)
	io.Pfyel("b = %v\n", b)
	chk.Ints(tst, "A", A, []int{1, 2, 3, 4, 5, 6, 7, 8})
	chk.Ints(tst, "B", B, []int{2, 4, 6, 8, 7, 5, 3, 1})
	chk.Ints(tst, "a", a, []int{4, 5, 6, 8, 7, 1, 2, 3})
	chk.Ints(tst, "b", b, []int{8, 7, 3, 4, 5, 1, 2, 6})
	sort.Ints(a)
	sort.Ints(b)
	nums := utl.IntRange2(1, 9)
	chk.Ints(tst, "asorted = 12345678", a, nums)
	chk.Ints(tst, "bsorted = 12345678", b, nums)

	A = []int{1, 3, 5, 7, 6, 2, 4, 8}
	B = []int{5, 6, 3, 8, 2, 1, 4, 7}
	ops.Cuts = []int{3, 6}
	IntOrdCrossover(a, b, A, B, 0, &ops)
	io.Pforan("\nA = %v\n", A)
	io.Pfblue2("B = %v\n", B)
	io.Pfgreen("a = %v\n", a)
	io.Pfyel("b = %v\n", b)
	chk.Ints(tst, "A", A, []int{1, 3, 5, 7, 6, 2, 4, 8})
	chk.Ints(tst, "B", B, []int{5, 6, 3, 8, 2, 1, 4, 7})
	chk.Ints(tst, "a", a, []int{5, 7, 6, 8, 2, 1, 4, 3})
	chk.Ints(tst, "b", b, []int{3, 8, 1, 7, 6, 2, 4, 5})
	sort.Ints(a)
	sort.Ints(b)
	chk.Ints(tst, "asorted = 12345678", a, nums)
	chk.Ints(tst, "bsorted = 12345678", b, nums)

	A = []int{1, 2, 3, 4, 5, 6, 7, 8}
	B = []int{2, 4, 6, 8, 7, 5, 3, 1}
	ops.Cuts = []int{}
	IntOrdCrossover(a, b, A, B, 0, &ops)
	io.Pforan("\nA = %v\n", A)
	io.Pfblue2("B = %v\n", B)
	io.Pfgreen("a = %v\n", a)
	io.Pfyel("b = %v\n", b)
	sort.Ints(a)
	sort.Ints(b)
	chk.Ints(tst, "asorted = 12345678", a, nums)
	chk.Ints(tst, "bsorted = 12345678", b, nums)

	C := []int{1, 2, 3}
	D := []int{3, 1, 2}
	c := make([]int, len(C))
	d := make([]int, len(D))
	IntOrdCrossover(c, d, C, D, 0, &ops)
	io.Pforan("\nC = %v\n", C)
	io.Pfblue2("D = %v\n", D)
	io.Pfgreen("c = %v\n", c)
	io.Pfyel("d = %v\n", d)
	chk.Ints(tst, "c", c, []int{2, 1, 3})
	chk.Ints(tst, "d", d, []int{1, 2, 3})
	sort.Ints(c)
	sort.Ints(d)
	chk.Ints(tst, "csorted = 123", c, []int{1, 2, 3})
	chk.Ints(tst, "dsorted = 123", d, []int{1, 2, 3})
}