go init
This commit is contained in:
		
							
								
								
									
										56
									
								
								bin/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								bin/main.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
			
		||||
package main
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"git.satori.love/gameui/weight"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	// 创建一个权重模型用于存储类型A的集合倾向节点(极点)A的权重
 | 
			
		||||
	weightModel := weight.NewWeightModel()
 | 
			
		||||
	// 添加权重
 | 
			
		||||
	weightModel.Add("A", 0.1)
 | 
			
		||||
	weightModel.Add("B", 0.2)
 | 
			
		||||
	weightModel.Add("C", 0.3)
 | 
			
		||||
	weightModel.Add("D", 0.4)
 | 
			
		||||
	// 排序
 | 
			
		||||
	weightModel.Weights.Sort()
 | 
			
		||||
	// 计算权重总和
 | 
			
		||||
	for _, v := range weightModel.Weights {
 | 
			
		||||
		weightModel.Total += v.Value
 | 
			
		||||
	}
 | 
			
		||||
	// 获取权重
 | 
			
		||||
	fmt.Println(weightModel.Get("A"))
 | 
			
		||||
	// 获取权重
 | 
			
		||||
	fmt.Println(weightModel.GetWeight("A"))
 | 
			
		||||
	// 获取权重列表
 | 
			
		||||
	fmt.Println(weightModel.GetWeightList())
 | 
			
		||||
	// 获取权重列表
 | 
			
		||||
	fmt.Println(weightModel.GetWeightListByValue())
 | 
			
		||||
	// 获取权重列表
 | 
			
		||||
	fmt.Println(weightModel.GetWeightListByValueDesc())
 | 
			
		||||
 | 
			
		||||
	// 创建一个权重模型用于存储类型B的集合倾向节点(极点)B的权重
 | 
			
		||||
	weightModel2 := weight.NewWeightModel()
 | 
			
		||||
	// 添加权重
 | 
			
		||||
	weightModel2.Add("A", 0.1)
 | 
			
		||||
	weightModel2.Add("B", 0.2)
 | 
			
		||||
	weightModel2.Add("C", 0.3)
 | 
			
		||||
	weightModel2.Add("D", 0.4)
 | 
			
		||||
	// 排序
 | 
			
		||||
	weightModel2.Weights.Sort()
 | 
			
		||||
	// 计算权重总和
 | 
			
		||||
	for _, v := range weightModel2.Weights {
 | 
			
		||||
		weightModel2.Total += v.Value
 | 
			
		||||
	}
 | 
			
		||||
	// 获取权重
 | 
			
		||||
	fmt.Println(weightModel2.Get("A"))
 | 
			
		||||
	// 获取权重
 | 
			
		||||
	fmt.Println(weightModel2.GetWeight("A"))
 | 
			
		||||
	// 获取权重列表
 | 
			
		||||
	fmt.Println(weightModel2.GetWeightList())
 | 
			
		||||
	// 获取权重列表
 | 
			
		||||
	fmt.Println(weightModel2.GetWeightListByValue())
 | 
			
		||||
	// 获取权重列表
 | 
			
		||||
	fmt.Println(weightModel2.GetWeightListByValueDesc())
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user