示例#1
0
func (v *Kp1Algo) Init(n int) {
	v.delta = real(cmath.Pow(complex(float64(n), 0), (-1.0 / 3)))
	v.u = real(cmath.Pow(complex(float64(n), 0), (1.0 / 3)))
	v.d = int(1 / (2 * v.delta))
	v.bins = make(map[int]*vector.Vector)
	for y := 0; y <= 2*v.d+1; y++ {
		vec := make(vector.Vector, 0)
		v.bins[y] = &vec
	}
}
示例#2
0
func checkMandelbrot(c complex128, res chan int) {
	z := settings.z0
	for i := 0; i < settings.repeat; i++ {
		z = cmath.Pow(z, settings.n) + c
		if 2.0 < cmath.Abs(cmath.Pow(z, 2)) {
			res <- i + 1
			return
		}
	}
	res <- -1
}
示例#3
0
func main() {
	prender := flag.Bool("r", false, "Render resulting alignment of all the rectangles")
	prenderbins = flag.Bool("rb", false, "Render bins")
	pnonsolid = flag.Bool("ns", false, "Non solid rendering of rectangles")
	pn := flag.Int("n", 100, "Number of rectangles")
	pm := flag.Int("m", 1, "Number of strips")
	pvalidate := flag.Bool("v", false, "Validate resulting alignment")
	palgo := flag.String("a", "kp2", "Type of algorithm")
	ptimes := flag.Int("t", 1, "Number of tests")
	flag.Parse()
	rand.Seed(time.Nanoseconds())

	println("Number of rectangles = ", *pn)
	fmt.Printf("N^(2/3) = %0.9v\n\n", real(cmath.Pow(complex(float64(*pn), 0), (2.0/3))))

	var coef_s float64 = 0
	for y := 0; y < *ptimes; y++ {
		coef := run(*pn, *prender, *pvalidate, *palgo, *pm)
		coef_s += coef
	}
	fmt.Printf("\nAverage coefficient = %0.9v\n", coef_s/float64(*ptimes))
}
示例#4
0
// Returns uncovered area divided by N^(2/3).
func run(n int, render, validate bool, algo_name string, m int) (coefficient float64) {
	rects := GenerateRectangles(n)
	var algo Algorithm

	if "kp1" == algo_name {
		algo = new(Kp1Algo)
	} else if "kp2" == algo_name {
		algo = new(Kp2Algo)
	} else if "2d" == algo_name {
		algo = new(TdAlgo)
	} else if "kp2_msp" == algo_name {
		algo = new(Kp2MspAlgo)
	} else if "kp2_msp_b" == algo_name {
		algo = new(Kp2MspBalancedAlgo)
	} else {
		algo = new(Kp2Algo)
	}

	H = algo.Pack(rects, 0, 0, m)
	total_area := TotalArea(rects)
	fmt.Printf("Solution height = %0.9v\nTotal area = %0.9v\n", H, total_area)
	uncovered_area := H*float64(m) - total_area
	fmt.Printf("Uncovered area = %0.9v\n", uncovered_area)
	coefficient = uncovered_area / real(cmath.Pow(complex(float64(n), 0), (2.0/3)))

	if true == validate {
		if false == Validate(rects, m, H) {
			println("Validation: ERROR")
		} else {
			println("Validation: OK")
		}
	}

	if render {
		render_all(rects, m)
	}
	return
}
示例#5
0
文件: cbrt.go 项目: ricbit/Oldies
func main() {
	fmt.Println(cmath.Pow(2, 1.0/3.0))
	fmt.Println(Cbrt(2))
}