本文整理汇总了Golang中container/vector.IntVector.Pop方法的典型用法代码示例。如果您正苦于以下问题:Golang IntVector.Pop方法的具体用法?Golang IntVector.Pop怎么用?Golang IntVector.Pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类container/vector.IntVector
的用法示例。
在下文中一共展示了IntVector.Pop方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Crossover
// Partially mapped crossover.
func (a *GAOrderedIntGenome) Crossover(bi GAGenome, p1, p2 int) (GAGenome, GAGenome) {
ca := a.Copy().(*GAOrderedIntGenome)
b := bi.(*GAOrderedIntGenome)
cb := b.Copy().(*GAOrderedIntGenome)
copy(ca.Gene[p1:p2+1], b.Gene[p1:p2+1])
copy(cb.Gene[p1:p2+1], a.Gene[p1:p2+1])
//Proto child needs fixing
amap := new(vector.IntVector)
bmap := new(vector.IntVector)
for i := p1; i <= p2; i++ {
ma, found := ca.pmxmap(ca.Gene[i], p1, p2)
if found {
amap.Push(ma)
if bmap.Len() > 0 {
i1 := amap.Pop()
i2 := bmap.Pop()
ca.Gene[i1], cb.Gene[i2] = cb.Gene[i2], ca.Gene[i1]
}
}
mb, found := cb.pmxmap(cb.Gene[i], p1, p2)
if found {
bmap.Push(mb)
if amap.Len() > 0 {
i1 := amap.Pop()
i2 := bmap.Pop()
ca.Gene[i1], cb.Gene[i2] = cb.Gene[i2], ca.Gene[i1]
}
}
}
ca.Reset()
cb.Reset()
return ca, cb
}
示例2: Qsort
func Qsort(list []interface{}, cmp func(a, b interface{}) int) (ret []interface{}, err os.Error) {
if len(list) <= 0 {
err = Error("len")
return
}
ret = make([]interface{}, len(list))
ret = list
stack := new(vector.IntVector)
stack.Push(0)
stack.Push(len(list) - 1)
for len(*stack) != 0 {
tail := stack.Pop()
head := stack.Pop()
pivot := ret[head+((tail-head)>>1)]
i := head - 1
j := tail + 1
for {
for i++; cmp(ret[i], pivot) < 0; i++ {
}
for j--; cmp(ret[j], pivot) > 0; j-- {
}
if i >= j {
break
}
tmp := ret[i]
ret[i] = ret[j]
ret[j] = tmp
}
if head < (i - 1) {
stack.Push(head)
stack.Push(i - 1)
}
if (j + 1) < tail {
stack.Push(j + 1)
stack.Push(tail)
}
}
return
}
示例3: RandomChan
// Sorts channels in random order
func (dbs *DBS) RandomChan() {
var SortCh vector.IntVector
for i := 0; i < NCh; i++ {
SortCh.Push(i)
dbs.RndCh[i] = i
}
//randomizesd reserved top canals
/* for i := 10; i > 1; i-- {
j := dbs.Rgen.Intn(i) + NCh-10
SortCh.Swap(NCh-10+i-1, j)
dbs.RndCh[NCh-10+i-1] =SortCh.Pop()
}
dbs.RndCh[NCh-10]=SortCh.Pop()
*/
//randomizes other canals
/* for i := NCh - 11; i > NChRes; i-- {
j := dbs.Rgen.Intn(i-NChRes) + NChRes
SortCh.Swap(i, j)
dbs.RndCh[i] =SortCh.Pop()
}
dbs.RndCh[NChRes] = SortCh.Pop()
dbs.RndCh[0] = 0
*/
//fmt.Println(dbs.RndCh);
for i := NCh - 1; i > NChRes; i-- {
j := dbs.Rgen.Intn(i-NChRes) + NChRes
SortCh.Swap(i, j)
dbs.RndCh[i] = SortCh.Pop()
}
dbs.RndCh[NChRes] = SortCh.Pop()
dbs.RndCh[0] = 0
}