自走棋羁绊搭配算法
2022/1/18 20:04:06
本文主要是介绍自走棋羁绊搭配算法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
自走棋羁绊搭配算法
#!/usr/bin/python3 # -*- coding: utf-8 -*- """ author: tuzichun ps : zl-sb """ import numpy as np import pandas as pd from itertools import combinations class Chess(object): # 初始化中给对象属性赋值 def __init__(self, trammels_x, trammels_y, name): self.X = trammels_x self.Y = trammels_y self.NAME = name def __str__(self): return self.NAME class Possibility(object): def __init__(self, chess_list): self.object_list = chess_list x_set = set() y_set = set() value_set = set() for wtf in self.object_list: x_set.add(wtf.X) y_set.add(wtf.Y) value_set.add(wtf.NAME) self.value = len(x_set) + len(y_set) self.count = len(value_set) def __str__(self): result = "" for wtf in self.object_list: result = result.join(wtf.NAME) + "," return result def generate_chess(): # 读取数据 result = [] csv_result = pd.read_csv("2321.csv", index_col=0) index_count = csv_result.shape[0] column_count = csv_result.shape[1] for wtf_x in range(0, index_count): for wtf_y in range(0, column_count): value = csv_result.iloc[wtf_x, wtf_y] if value != np.NAN: result.append(Chess(wtf_x, wtf_y, value)) return result if __name__ == '__main__': Chess_list = generate_chess() dataframe_result = pd.DataFrame(columns=['combination', 'value', 'count']) for x in range(3, 11): dataframe_result_part = pd.DataFrame(columns=['combination', 'value', 'count']) a = [] res = list(combinations(Chess_list, x)) if len(res) != 0: for y in res: y = list(y) deal = Possibility(y) if deal.value != 2 * x: dataframe_result_part['combination'].append(str(deal)) dataframe_result_part['value'].append(deal.value) dataframe_result_part['count'].append(deal.count) else: continue dataframe_result.append(dataframe_result_part) dataframe_result = dataframe_result.sort_values(by=["value", "count"], ascending=(True, False)) dataframe_result.to_csv("1.csv")
这篇关于自走棋羁绊搭配算法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-10百万架构师第十三课:源码分析:Spring 源码分析:Spring核心IOC容器及依赖注入原理|JavaGuide
- 2025-01-10便捷好用的电商API工具合集
- 2025-01-09必试!帮 J 人团队解决物流错发漏发的软件神器!
- 2025-01-09不容小觑!助力 J 人物流客服安抚情绪的软件!
- 2025-01-09为什么医疗团队协作离不开智能文档工具?
- 2025-01-09惊叹:J 人团队用啥软件让物流服务快又准?
- 2025-01-09如何利用数据分析工具优化项目资源分配?4种工具推荐
- 2025-01-09多学科协作难?这款文档工具可以帮你省心省力
- 2025-01-09团队中的技术项目经理TPM:工作内容与资源优化策略
- 2025-01-09JIT生产管理法:优化流程,提升竞争力的秘诀