[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-guofei9987--scikit-opt":3,"tool-guofei9987--scikit-opt":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":80,"owner_email":81,"owner_twitter":78,"owner_website":82,"owner_url":83,"languages":84,"stars":93,"forks":94,"last_commit_at":95,"license":96,"difficulty_score":97,"env_os":98,"env_gpu":99,"env_ram":99,"env_deps":100,"category_tags":108,"github_topics":109,"view_count":123,"oss_zip_url":78,"oss_zip_packed_at":78,"status":16,"created_at":124,"updated_at":125,"faqs":126,"releases":156},503,"guofei9987\u002Fscikit-opt","scikit-opt","Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Optimization Algorithm,Immune Algorithm, Artificial Fish Swarm Algorithm, Differential Evolution and TSP(Traveling salesman) ","scikit-opt 是一款基于 Python 的开源智能优化算法库，旨在为复杂问题的求解提供高效的计算方案。它集成了遗传算法、粒子群优化、模拟退火、蚁群算法、免疫算法及差分进化等多种经典群体智能策略，特别擅长处理非线性函数优化与组合优化难题，如旅行商路径规划等场景。\n\n面对传统方法难以收敛或效率低下的优化挑战，scikit-opt 通过成熟的算法封装降低了使用门槛。它非常适合算法工程师、数据科学家以及高校研究人员在机器学习调参、工程调度或科研建模中使用。\n\n其独特的技术亮点在于对自定义算子（UDF）的支持。开发者可以灵活定义选择、交叉、变异等核心操作逻辑，从而针对特定问题定制专属算法流程。配合简洁的 pip 安装命令和多平台兼容性，scikit-opt 让智能优化算法的落地变得既专业又便捷，是 Python 生态中值得信赖的优化工具库。","\n# [scikit-opt](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt)\n\n[![PyPI](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Fscikit-opt)](https:\u002F\u002Fpypi.org\u002Fproject\u002Fscikit-opt\u002F)\n[![Build Status](https:\u002F\u002Ftravis-ci.com\u002Fguofei9987\u002Fscikit-opt.svg?branch=master)](https:\u002F\u002Ftravis-ci.com\u002Fguofei9987\u002Fscikit-opt)\n[![codecov](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fguofei9987\u002Fscikit-opt\u002Fbranch\u002Fmaster\u002Fgraph\u002Fbadge.svg)](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fguofei9987\u002Fscikit-opt)\n[![License](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fl\u002Fscikit-opt.svg)](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002FLICENSE)\n![Python](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpython->=3.5-green.svg)\n![Platform](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fplatform-windows%20|%20linux%20|%20macos-green.svg)\n[![fork](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fforks\u002Fguofei9987\u002Fscikit-opt?style=social)](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Ffork)\n[![Downloads](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_50b4802822bd.png)](https:\u002F\u002Fpepy.tech\u002Fproject\u002Fscikit-opt)\n[![Discussions](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fdiscussions-green.svg)](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fdiscussions)\n\u003Ca href=\"https:\u002F\u002Fhellogithub.com\u002Frepository\u002Fguofei9987\u002Fscikit-opt\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fabroad.hellogithub.com\u002Fv1\u002Fwidgets\u002Frecommend.svg?rid=6763d615842e4449a02f024f3e2e345c&claim_uid=se0WHo8cbiLv2w1&theme=small\" alt=\"Featured｜HelloGitHub\" \u002F>\u003C\u002Fa>\n\n\nSwarm Intelligence in Python  \n(Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Algorithm, Immune Algorithm, Artificial Fish Swarm Algorithm in Python)\n\n\n- **Documentation:** [https:\u002F\u002Fscikit-opt.github.io\u002Fscikit-opt\u002F#\u002Fen\u002F](https:\u002F\u002Fscikit-opt.github.io\u002Fscikit-opt\u002F#\u002Fen\u002F)\n- **文档：** [https:\u002F\u002Fscikit-opt.github.io\u002Fscikit-opt\u002F#\u002Fzh\u002F](https:\u002F\u002Fscikit-opt.github.io\u002Fscikit-opt\u002F#\u002Fzh\u002F)  \n- **Source code:** [https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt)\n- **Help us improve scikit-opt** [https:\u002F\u002Fwww.wjx.cn\u002Fjq\u002F50964691.aspx](https:\u002F\u002Fwww.wjx.cn\u002Fjq\u002F50964691.aspx)\n\n# install\n```bash\npip install scikit-opt\n```\n\nFor the current developer version:\n```bach\ngit clone git@github.com:guofei9987\u002Fscikit-opt.git\ncd scikit-opt\npip install .\n```\n\n# Features\n## Feature1: UDF\n\n**UDF** (user defined function) is available now!\n\nFor example, you just worked out a new type of `selection` function.  \nNow, your `selection` function is like this:  \n-> Demo code: [examples\u002Fdemo_ga_udf.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_udf.py#L1)\n```python\n# step1: define your own operator:\ndef selection_tournament(algorithm, tourn_size):\n    FitV = algorithm.FitV\n    sel_index = []\n    for i in range(algorithm.size_pop):\n        aspirants_index = np.random.choice(range(algorithm.size_pop), size=tourn_size)\n        sel_index.append(max(aspirants_index, key=lambda i: FitV[i]))\n    algorithm.Chrom = algorithm.Chrom[sel_index, :]  # next generation\n    return algorithm.Chrom\n\n\n```\n\nImport and build ga  \n-> Demo code: [examples\u002Fdemo_ga_udf.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_udf.py#L12)\n```python\nimport numpy as np\nfrom sko.GA import GA, GA_TSP\n\ndemo_func = lambda x: x[0] ** 2 + (x[1] - 0.05) ** 2 + (x[2] - 0.5) ** 2\nga = GA(func=demo_func, n_dim=3, size_pop=100, max_iter=500, prob_mut=0.001,\n        lb=[-1, -10, -5], ub=[2, 10, 2], precision=[1e-7, 1e-7, 1])\n\n```\nRegist your udf to GA  \n-> Demo code: [examples\u002Fdemo_ga_udf.py#s3](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_udf.py#L20)\n```python\nga.register(operator_name='selection', operator=selection_tournament, tourn_size=3)\n```\n\nscikit-opt also provide some operators  \n-> Demo code: [examples\u002Fdemo_ga_udf.py#s4](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_udf.py#L22)\n```python\nfrom sko.operators import ranking, selection, crossover, mutation\n\nga.register(operator_name='ranking', operator=ranking.ranking). \\\n    register(operator_name='crossover', operator=crossover.crossover_2point). \\\n    register(operator_name='mutation', operator=mutation.mutation)\n```\nNow do GA as usual  \n-> Demo code: [examples\u002Fdemo_ga_udf.py#s5](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_udf.py#L28)\n```python\nbest_x, best_y = ga.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n```\n\n> Until Now, the **udf** surport `crossover`, `mutation`, `selection`, `ranking` of GA\n> scikit-opt provide a dozen of operators, see [here](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Ftree\u002Fmaster\u002Fsko\u002Foperators)\n\nFor advanced users:\n\n-> Demo code: [examples\u002Fdemo_ga_udf.py#s6](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_udf.py#L31)\n```python\nclass MyGA(GA):\n    def selection(self, tourn_size=3):\n        FitV = self.FitV\n        sel_index = []\n        for i in range(self.size_pop):\n            aspirants_index = np.random.choice(range(self.size_pop), size=tourn_size)\n            sel_index.append(max(aspirants_index, key=lambda i: FitV[i]))\n        self.Chrom = self.Chrom[sel_index, :]  # next generation\n        return self.Chrom\n\n    ranking = ranking.ranking\n\n\ndemo_func = lambda x: x[0] ** 2 + (x[1] - 0.05) ** 2 + (x[2] - 0.5) ** 2\nmy_ga = MyGA(func=demo_func, n_dim=3, size_pop=100, max_iter=500, lb=[-1, -10, -5], ub=[2, 10, 2],\n             precision=[1e-7, 1e-7, 1])\nbest_x, best_y = my_ga.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n```\n\n##  feature2: continue to run\n(New in version 0.3.6)  \nRun an algorithm for 10 iterations, and then run another 20 iterations base on the 10 iterations before:\n```python\nfrom sko.GA import GA\n\nfunc = lambda x: x[0] ** 2\nga = GA(func=func, n_dim=1)\nga.run(10)\nga.run(20)\n```\n\n## feature3: 4-ways to accelerate\n- vectorization\n- multithreading\n- multiprocessing\n- cached\n\nsee [https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fexample_function_modes.py](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fexample_function_modes.py)\n\n\n\n## feature4: GPU computation\n We are developing GPU computation, which will be stable on version 1.0.0  \nAn example is already available: [https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_gpu.py](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_gpu.py)\n\n\n# Quick start\n\n## 1. Differential Evolution\n**Step1**：define your problem  \n-> Demo code: [examples\u002Fdemo_de.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_de.py#L1)\n```python\n'''\nmin f(x1, x2, x3) = x1^2 + x2^2 + x3^2\ns.t.\n    x1*x2 >= 1\n    x1*x2 \u003C= 5\n    x2 + x3 = 1\n    0 \u003C= x1, x2, x3 \u003C= 5\n'''\n\n\ndef obj_func(p):\n    x1, x2, x3 = p\n    return x1 ** 2 + x2 ** 2 + x3 ** 2\n\n\nconstraint_eq = [\n    lambda x: 1 - x[1] - x[2]\n]\n\nconstraint_ueq = [\n    lambda x: 1 - x[0] * x[1],\n    lambda x: x[0] * x[1] - 5\n]\n\n```\n\n**Step2**: do Differential Evolution  \n-> Demo code: [examples\u002Fdemo_de.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_de.py#L25)\n```python\nfrom sko.DE import DE\n\nde = DE(func=obj_func, n_dim=3, size_pop=50, max_iter=800, lb=[0, 0, 0], ub=[5, 5, 5],\n        constraint_eq=constraint_eq, constraint_ueq=constraint_ueq)\n\nbest_x, best_y = de.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n\n```\n\n## 2. Genetic Algorithm\n\n**Step1**：define your problem  \n-> Demo code: [examples\u002Fdemo_ga.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga.py#L1)\n```python\nimport numpy as np\n\n\ndef schaffer(p):\n    '''\n    This function has plenty of local minimum, with strong shocks\n    global minimum at (0,0) with value 0\n    https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FTest_functions_for_optimization\n    '''\n    x1, x2 = p\n    part1 = np.square(x1) - np.square(x2)\n    part2 = np.square(x1) + np.square(x2)\n    return 0.5 + (np.square(np.sin(part1)) - 0.5) \u002F np.square(1 + 0.001 * part2)\n\n\n```\n\n**Step2**: do Genetic Algorithm  \n-> Demo code: [examples\u002Fdemo_ga.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga.py#L16)\n```python\nfrom sko.GA import GA\n\nga = GA(func=schaffer, n_dim=2, size_pop=50, max_iter=800, prob_mut=0.001, lb=[-1, -1], ub=[1, 1], precision=1e-7)\nbest_x, best_y = ga.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n```\n\n-> Demo code: [examples\u002Fdemo_ga.py#s3](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga.py#L22)\n```python\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\nY_history = pd.DataFrame(ga.all_history_Y)\nfig, ax = plt.subplots(2, 1)\nax[0].plot(Y_history.index, Y_history.values, '.', color='red')\nY_history.min(axis=1).cummin().plot(kind='line')\nplt.show()\n```\n\n![Figure_1-1](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_1981ff284b69.png)\n\n### 2.2 Genetic Algorithm for TSP(Travelling Salesman Problem)\nJust import the `GA_TSP`, it overloads the `crossover`, `mutation` to solve the TSP\n\n**Step1**: define your problem. Prepare your points coordinate and the distance matrix.  \nHere I generate the data randomly as a demo:  \n-> Demo code: [examples\u002Fdemo_ga_tsp.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_tsp.py#L1)\n```python\nimport numpy as np\nfrom scipy import spatial\nimport matplotlib.pyplot as plt\n\nnum_points = 50\n\npoints_coordinate = np.random.rand(num_points, 2)  # generate coordinate of points\ndistance_matrix = spatial.distance.cdist(points_coordinate, points_coordinate, metric='euclidean')\n\n\ndef cal_total_distance(routine):\n    '''The objective function. input routine, return total distance.\n    cal_total_distance(np.arange(num_points))\n    '''\n    num_points, = routine.shape\n    return sum([distance_matrix[routine[i % num_points], routine[(i + 1) % num_points]] for i in range(num_points)])\n\n\n```\n\n**Step2**: do GA  \n-> Demo code: [examples\u002Fdemo_ga_tsp.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_tsp.py#L19)\n```python\n\nfrom sko.GA import GA_TSP\n\nga_tsp = GA_TSP(func=cal_total_distance, n_dim=num_points, size_pop=50, max_iter=500, prob_mut=1)\nbest_points, best_distance = ga_tsp.run()\n\n```\n\n**Step3**: Plot the result:  \n-> Demo code: [examples\u002Fdemo_ga_tsp.py#s3](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_tsp.py#L26)\n```python\nfig, ax = plt.subplots(1, 2)\nbest_points_ = np.concatenate([best_points, [best_points[0]]])\nbest_points_coordinate = points_coordinate[best_points_, :]\nax[0].plot(best_points_coordinate[:, 0], best_points_coordinate[:, 1], 'o-r')\nax[1].plot(ga_tsp.generation_best_Y)\nplt.show()\n```\n\n![GA_TPS](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_98b1861ecd44.png)\n\n\n## 3. PSO(Particle swarm optimization)\n\n### 3.1 PSO\n**Step1**: define your problem:  \n-> Demo code: [examples\u002Fdemo_pso.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_pso.py#L1)\n```python\ndef demo_func(x):\n    x1, x2, x3 = x\n    return x1 ** 2 + (x2 - 0.05) ** 2 + x3 ** 2\n\n\n```\n\n**Step2**: do PSO  \n-> Demo code: [examples\u002Fdemo_pso.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_pso.py#L6)\n```python\nfrom sko.PSO import PSO\n\npso = PSO(func=demo_func, n_dim=3, pop=40, max_iter=150, lb=[0, -1, 0.5], ub=[1, 1, 1], w=0.8, c1=0.5, c2=0.5)\npso.run()\nprint('best_x is ', pso.gbest_x, 'best_y is', pso.gbest_y)\n\n```\n\n**Step3**: Plot the result  \n-> Demo code: [examples\u002Fdemo_pso.py#s3](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_pso.py#L13)\n```python\nimport matplotlib.pyplot as plt\n\nplt.plot(pso.gbest_y_hist)\nplt.show()\n```\n\n\n![PSO_TPS](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_01da90411fe1.png)\n\n### 3.2 PSO with nonlinear constraint\n\nIf you need nolinear constraint like `(x[0] - 1) ** 2 + (x[1] - 0) ** 2 - 0.5 ** 2\u003C=0`  \nCodes are like this:\n```python\nconstraint_ueq = (\n    lambda x: (x[0] - 1) ** 2 + (x[1] - 0) ** 2 - 0.5 ** 2\n    ,\n)\npso = PSO(func=demo_func, n_dim=2, pop=40, max_iter=max_iter, lb=[-2, -2], ub=[2, 2]\n          , constraint_ueq=constraint_ueq)\n```\n\nNote that, you can add more then one nonlinear constraint. Just add it to `constraint_ueq`\n\nMore over, we have an animation:  \n![pso_ani](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_aae3067a4039.gif)  \n↑**see [examples\u002Fdemo_pso_ani.py](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_pso_ani.py)**\n\n\n## 4. SA(Simulated Annealing)\n### 4.1 SA for multiple function\n**Step1**: define your problem  \n-> Demo code: [examples\u002Fdemo_sa.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_sa.py#L1)\n```python\ndemo_func = lambda x: x[0] ** 2 + (x[1] - 0.05) ** 2 + x[2] ** 2\n\n```\n**Step2**: do SA  \n-> Demo code: [examples\u002Fdemo_sa.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_sa.py#L3)\n```python\nfrom sko.SA import SA\n\nsa = SA(func=demo_func, x0=[1, 1, 1], T_max=1, T_min=1e-9, L=300, max_stay_counter=150)\nbest_x, best_y = sa.run()\nprint('best_x:', best_x, 'best_y', best_y)\n\n```\n\n**Step3**: Plot the result  \n-> Demo code: [examples\u002Fdemo_sa.py#s3](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_sa.py#L10)\n```python\nimport matplotlib.pyplot as plt\nimport pandas as pd\n\nplt.plot(pd.DataFrame(sa.best_y_history).cummin(axis=0))\nplt.show()\n\n```\n![sa](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_97aa0f703d15.png)\n\n\nMoreover, scikit-opt provide 3 types of Simulated Annealing: Fast, Boltzmann, Cauchy. See [more sa](https:\u002F\u002Fscikit-opt.github.io\u002Fscikit-opt\u002F#\u002Fen\u002Fmore_sa)\n### 4.2 SA for TSP\n**Step1**: oh, yes, define your problems. To boring to copy this step.  \n\n**Step2**: DO SA for TSP  \n-> Demo code: [examples\u002Fdemo_sa_tsp.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_sa_tsp.py#L21)\n```python\nfrom sko.SA import SA_TSP\n\nsa_tsp = SA_TSP(func=cal_total_distance, x0=range(num_points), T_max=100, T_min=1, L=10 * num_points)\n\nbest_points, best_distance = sa_tsp.run()\nprint(best_points, best_distance, cal_total_distance(best_points))\n```\n\n**Step3**: plot the result  \n-> Demo code: [examples\u002Fdemo_sa_tsp.py#s3](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_sa_tsp.py#L28)\n```python\nfrom matplotlib.ticker import FormatStrFormatter\n\nfig, ax = plt.subplots(1, 2)\n\nbest_points_ = np.concatenate([best_points, [best_points[0]]])\nbest_points_coordinate = points_coordinate[best_points_, :]\nax[0].plot(sa_tsp.best_y_history)\nax[0].set_xlabel(\"Iteration\")\nax[0].set_ylabel(\"Distance\")\nax[1].plot(best_points_coordinate[:, 0], best_points_coordinate[:, 1],\n           marker='o', markerfacecolor='b', color='c', linestyle='-')\nax[1].xaxis.set_major_formatter(FormatStrFormatter('%.3f'))\nax[1].yaxis.set_major_formatter(FormatStrFormatter('%.3f'))\nax[1].set_xlabel(\"Longitude\")\nax[1].set_ylabel(\"Latitude\")\nplt.show()\n\n```\n![sa](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_73940b6b99a0.png)\n\n\nMore: Plot the animation:  \n\n![sa](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_a3eb5c0e9d41.gif)  \n↑**see [examples\u002Fdemo_sa_tsp.py](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_sa_tsp.py)**\n\n\n\n\n## 5. ACA (Ant Colony Algorithm) for tsp\n-> Demo code: [examples\u002Fdemo_aca_tsp.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_aca_tsp.py#L17)\n```python\nfrom sko.ACA import ACA_TSP\n\naca = ACA_TSP(func=cal_total_distance, n_dim=num_points,\n              size_pop=50, max_iter=200,\n              distance_matrix=distance_matrix)\n\nbest_x, best_y = aca.run()\n\n```\n\n![ACA](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_c368df1fdac3.png)\n\n\n## 6. immune algorithm (IA)\n-> Demo code: [examples\u002Fdemo_ia.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ia.py#L6)\n```python\n\nfrom sko.IA import IA_TSP\n\nia_tsp = IA_TSP(func=cal_total_distance, n_dim=num_points, size_pop=500, max_iter=800, prob_mut=0.2,\n                T=0.7, alpha=0.95)\nbest_points, best_distance = ia_tsp.run()\nprint('best routine:', best_points, 'best_distance:', best_distance)\n\n```\n\n![IA](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_30a9eabcd22e.png)\n\n## 7. Artificial Fish Swarm Algorithm (AFSA)\n-> Demo code: [examples\u002Fdemo_afsa.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_afsa.py#L1)\n```python\ndef func(x):\n    x1, x2 = x\n    return 1 \u002F x1 ** 2 + x1 ** 2 + 1 \u002F x2 ** 2 + x2 ** 2\n\n\nfrom sko.AFSA import AFSA\n\nafsa = AFSA(func, n_dim=2, size_pop=50, max_iter=300,\n            max_try_num=100, step=0.5, visual=0.3,\n            q=0.98, delta=0.5)\nbest_x, best_y = afsa.run()\nprint(best_x, best_y)\n```\n\n\n\n# Projects using scikit-opt\n\n- [Yu, J., He, Y., Yan, Q., & Kang, X. (2021). SpecView: Malware Spectrum Visualization Framework With Singular Spectrum Transformation. IEEE Transactions on Information Forensics and Security, 16, 5093-5107.](https:\u002F\u002Fieeexplore.ieee.org\u002Fabstract\u002Fdocument\u002F9607026\u002F)\n- [Zhen, H., Zhai, H., Ma, W., Zhao, L., Weng, Y., Xu, Y., ... & He, X. (2021). Design and tests of reinforcement-learning-based optimal power flow solution generator. Energy Reports.](https:\u002F\u002Fwww.sciencedirect.com\u002Fscience\u002Farticle\u002Fpii\u002FS2352484721012737)\n- [Heinrich, K., Zschech, P., Janiesch, C., & Bonin, M. (2021). Process data properties matter: Introducing gated convolutional neural networks (GCNN) and key-value-predict attention networks (KVP) for next event prediction with deep learning. Decision Support Systems, 143, 113494.](https:\u002F\u002Fwww.sciencedirect.com\u002Fscience\u002Farticle\u002Fpii\u002FS016792362100004X)\n- [Tang, H. K., & Goh, S. K. (2021). A Novel Non-population-based Meta-heuristic Optimizer Inspired by the Philosophy of Yi Jing. arXiv preprint arXiv:2104.08564.](https:\u002F\u002Farxiv.org\u002Fabs\u002F2104.08564)\n- [Wu, G., Li, L., Li, X., Chen, Y., Chen, Z., Qiao, B., ... & Xia, L. (2021). Graph embedding based real-time social event matching for EBSNs recommendation. World Wide Web, 1-22.](https:\u002F\u002Flink.springer.com\u002Farticle\u002F10.1007\u002Fs11280-021-00934-y)\n- [Pan, X., Zhang, Z., Zhang, H., Wen, Z., Ye, W., Yang, Y., ... & Zhao, X. (2021). A fast and robust mixture gases identification and concentration detection algorithm based on attention mechanism equipped recurrent neural network with double loss function. Sensors and Actuators B: Chemical, 342, 129982.](https:\u002F\u002Fwww.sciencedirect.com\u002Fscience\u002Farticle\u002Fabs\u002Fpii\u002FS0925400521005517)\n- [Castella Balcell, M. (2021). Optimization of the station keeping system for the WindCrete floating offshore wind turbine.](https:\u002F\u002Fupcommons.upc.edu\u002Fhandle\u002F2117\u002F350262)\n- [Zhai, B., Wang, Y., Wang, W., & Wu, B. (2021). Optimal Variable Speed Limit Control Strategy on Freeway Segments under Fog Conditions. arXiv preprint arXiv:2107.14406.](https:\u002F\u002Farxiv.org\u002Fabs\u002F2107.14406)\n- [Yap, X. H. (2021). Multi-label classification on locally-linear data: Application to chemical toxicity prediction.](https:\u002F\u002Fetd.ohiolink.edu\u002Fapexprod\u002Frws_olink\u002Fr\u002F1501\u002F10?clear=10&p10_accession_num=wright162901936395651)\n- [Gebhard, L. (2021). Expansion Planning of Low-Voltage Grids Using Ant Colony Optimization Ausbauplanung von Niederspannungsnetzen mithilfe eines Ameisenalgorithmus.](https:\u002F\u002Fad-publications.cs.uni-freiburg.de\u002Ftheses\u002FMaster_Lukas_Gebhard_2021.pdf)\n- [Ma, X., Zhou, H., & Li, Z. (2021). Optimal Design for Interdependencies between Hydrogen and Power Systems. IEEE Transactions on Industry Applications.](https:\u002F\u002Fieeexplore.ieee.org\u002Fabstract\u002Fdocument\u002F9585654)\n- [de Curso, T. D. C. (2021). Estudo do modelo Johansen-Ledoit-Sornette de bolhas financeiras.](https:\u002F\u002Fd1wqtxts1xzle7.cloudfront.net\u002F67649721\u002FTCC_Thibor_Final-with-cover-page-v2.pdf?Expires=1639140872&Signature=LDZoVsAGO0mLMlVsQjnzpLlRhLyt5wdIDmBjm1yWog5bsx6apyRE9aHuwfnFnc96uvam573wiHMeV08QlK2vhRcQS1d0buenBT5fwoRuq6PTDoMsXmpBb-lGtu9ETiMb4sBYvcQb-X3C7Hh0Ec1FoJZ040gXJPWdAli3e1TdOcGrnOaBZMgNiYX6aKFIZaaXmiQeV3418~870bH4IOQXOapIE6-23lcOL-32T~FSjsOrENoLUkcosv6UHPourKgsRufAY-C2HBUWP36iJ7CoH0jSTo1e45dVgvqNDvsHz7tmeI~0UPGH-A8MWzQ9h2ElCbCN~UNQ8ycxOa4TUKfpCw__&Key-Pair-Id=APKAJLOHF5GGSLRBV4ZA)\n- [Wu, T., Liu, J., Liu, J., Huang, Z., Wu, H., Zhang, C., ... & Zhang, G. (2021). A Novel AI-based Framework for AoI-optimal Trajectory Planning in UAV-assisted Wireless Sensor Networks. IEEE Transactions on Wireless Communications.](https:\u002F\u002Fieeexplore.ieee.org\u002Fabstract\u002Fdocument\u002F9543607)\n- [Liu, H., Wen, Z., & Cai, W. (2021, August). FastPSO: Towards Efficient Swarm Intelligence Algorithm on GPUs. In 50th International Conference on Parallel Processing (pp. 1-10).](https:\u002F\u002Fdl.acm.org\u002Fdoi\u002Fabs\u002F10.1145\u002F3472456.3472474)\n- [Mahbub, R. (2020). Algorithms and Optimization Techniques for Solving TSP.](https:\u002F\u002Fraiyanmahbub.com\u002Fimages\u002FResearch_Paper.pdf)\n- [Li, J., Chen, T., Lim, K., Chen, L., Khan, S. A., Xie, J., & Wang, X. (2019). Deep learning accelerated gold nanocluster synthesis. Advanced Intelligent Systems, 1(3), 1900029.](https:\u002F\u002Fonlinelibrary.wiley.com\u002Fdoi\u002Ffull\u002F10.1002\u002Faisy.201900029)\n","# [scikit-opt](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt)\n\n[![PyPI](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Fscikit-opt)](https:\u002F\u002Fpypi.org\u002Fproject\u002Fscikit-opt\u002F)\n[![Build Status](https:\u002F\u002Ftravis-ci.com\u002Fguofei9987\u002Fscikit-opt.svg?branch=master)](https:\u002F\u002Ftravis-ci.com\u002Fguofei9987\u002Fscikit-opt)\n[![codecov](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fguofei9987\u002Fscikit-opt\u002Fbranch\u002Fmaster\u002Fgraph\u002Fbadge.svg)](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fguofei9987\u002Fscikit-opt)\n[![License](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fl\u002Fscikit-opt.svg)](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002FLICENSE)\n![Python](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpython->=3.5-green.svg)\n![Platform](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fplatform-windows%20|%20linux%20|%20macos-green.svg)\n[![fork](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fforks\u002Fguofei9987\u002Fscikit-opt?style=social)](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Ffork)\n[![Downloads](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_50b4802822bd.png)](https:\u002F\u002Fpepy.tech\u002Fproject\u002Fscikit-opt)\n[![Discussions](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fdiscussions-green.svg)](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fdiscussions)\n\u003Ca href=\"https:\u002F\u002Fhellogithub.com\u002Frepository\u002Fguofei9987\u002Fscikit-opt\" target=\"_blank\">\u003Cimg src=\"https:\u002F\u002Fabroad.hellogithub.com\u002Fv1\u002Fwidgets\u002Frecommend.svg?rid=6763d615842e4449a02f024f3e2e345c&claim_uid=se0WHo8cbiLv2w1&theme=small\" alt=\"Featured｜HelloGitHub\" \u002F>\u003C\u002Fa>\n\n\nPython 中的群体智能  \n（遗传算法、粒子群优化、模拟退火、蚁群算法、免疫算法、人工鱼群算法）\n\n\n- **文档：** [https:\u002F\u002Fscikit-opt.github.io\u002Fscikit-opt\u002F#\u002Fen\u002F](https:\u002F\u002Fscikit-opt.github.io\u002Fscikit-opt\u002F#\u002Fen\u002F)\n- **文档：** [https:\u002F\u002Fscikit-opt.github.io\u002Fscikit-opt\u002F#\u002Fzh\u002F](https:\u002F\u002Fscikit-opt.github.io\u002Fscikit-opt\u002F#\u002Fzh\u002F)  \n- **源代码：** [https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt)\n- **帮助我们改进 scikit-opt** [https:\u002F\u002Fwww.wjx.cn\u002Fjq\u002F50964691.aspx](https:\u002F\u002Fwww.wjx.cn\u002Fjq\u002F50964691.aspx)\n\n# 安装\n```bash\npip install scikit-opt\n```\n\n对于当前的开发版本：\n```bach\ngit clone git@github.com:guofei9987\u002Fscikit-opt.git\ncd scikit-opt\npip install .\n```\n\n# 功能特性\n## 功能一：UDF（用户自定义函数）\n\n**UDF**（用户自定义函数，User Defined Function）现已可用！\n\n例如，你刚刚设计了一种新的 `selection`（选择）函数。  \n现在，你的 `selection` 函数如下所示：  \n-> 演示代码：[examples\u002Fdemo_ga_udf.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_udf.py#L1)\n```python\n# step1: define your own operator:\ndef selection_tournament(algorithm, tourn_size):\n    FitV = algorithm.FitV\n    sel_index = []\n    for i in range(algorithm.size_pop):\n        aspirants_index = np.random.choice(range(algorithm.size_pop), size=tourn_size)\n        sel_index.append(max(aspirants_index, key=lambda i: FitV[i]))\n    algorithm.Chrom = algorithm.Chrom[sel_index, :]  # next generation\n    return algorithm.Chrom\n\n\n```\n\n导入并构建 GA（遗传算法）  \n-> 演示代码：[examples\u002Fdemo_ga_udf.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_udf.py#L12)\n```python\nimport numpy as np\nfrom sko.GA import GA, GA_TSP\n\ndemo_func = lambda x: x[0] ** 2 + (x[1] - 0.05) ** 2 + (x[2] - 0.5) ** 2\nga = GA(func=demo_func, n_dim=3, size_pop=100, max_iter=500, prob_mut=0.001,\n        lb=[-1, -10, -5], ub=[2, 10, 2], precision=[1e-7, 1e-7, 1])\n\n```\n将你的 UDF 注册到 GA  \n-> 演示代码：[examples\u002Fdemo_ga_udf.py#s3](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_udf.py#L20)\n```python\nga.register(operator_name='selection', operator=selection_tournament, tourn_size=3)\n```\n\nscikit-opt 还提供了一些算子  \n-> 演示代码：[examples\u002Fdemo_ga_udf.py#s4](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_udf.py#L22)\n```python\nfrom sko.operators import ranking, selection, crossover, mutation\n\nga.register(operator_name='ranking', operator=ranking.ranking). \\\n    register(operator_name='crossover', operator=crossover.crossover_2point). \\\n    register(operator_name='mutation', operator=mutation.mutation)\n```\n现在像往常一样运行 GA  \n-> 演示代码：[examples\u002Fdemo_ga_udf.py#s5](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_udf.py#L28)\n```python\nbest_x, best_y = ga.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n```\n\n> 截至目前，**udf** 支持 GA 的 `crossover`（交叉）、`mutation`（变异）、`selection`（选择）、`ranking`（排序）\n> scikit-opt 提供了一打以上的算子，详见 [此处](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Ftree\u002Fmaster\u002Fsko\u002Foperators)\n\n针对高级用户：\n\n-> 演示代码：[examples\u002Fdemo_ga_udf.py#s6](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_udf.py#L31)\n```python\nclass MyGA(GA):\n    def selection(self, tourn_size=3):\n        FitV = self.FitV\n        sel_index = []\n        for i in range(self.size_pop):\n            aspirants_index = np.random.choice(range(self.size_pop), size=tourn_size)\n            sel_index.append(max(aspirants_index, key=lambda i: FitV[i]))\n        self.Chrom = self.Chrom[sel_index, :]  # next generation\n        return self.Chrom\n\n    ranking = ranking.ranking\n\n\ndemo_func = lambda x: x[0] ** 2 + (x[1] - 0.05) ** 2 + (x[2] - 0.5) ** 2\nmy_ga = MyGA(func=demo_func, n_dim=3, size_pop=100, max_iter=500, lb=[-1, -10, -5], ub=[2, 10, 2],\n             precision=[1e-7, 1e-7, 1])\nbest_x, best_y = my_ga.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n```\n\n## 功能二：继续运行\n（v0.3.6 新增）  \n先运行算法 10 次迭代，然后基于之前的 10 次迭代再运行另外 20 次迭代：\n```python\nfrom sko.GA import GA\n\nfunc = lambda x: x[0] ** 2\nga = GA(func=func, n_dim=1)\nga.run(10)\nga.run(20)\n```\n\n## 功能三：4 种加速方式\n- vectorization（向量化）\n- multithreading（多线程）\n- multiprocessing（多进程）\n- cached（缓存）\n\n参见 [https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fexample_function_modes.py](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fexample_function_modes.py)\n\n\n\n## 功能四：GPU 计算\n我们正在开发 GPU 计算功能，该功能将在 1.0.0 版本中稳定。  \n示例已可用：[https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_gpu.py](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_gpu.py)\n\n\n# 快速开始\n\n## 1. 差分进化算法 (Differential Evolution)\n**步骤 1**：定义你的问题  \n-> 示例代码：[examples\u002Fdemo_de.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_de.py#L1)\n```python\n'''\nmin f(x1, x2, x3) = x1^2 + x2^2 + x3^2\ns.t.\n    x1*x2 >= 1\n    x1*x2 \u003C= 5\n    x2 + x3 = 1\n    0 \u003C= x1, x2, x3 \u003C= 5\n'''\n\n\ndef obj_func(p):\n    x1, x2, x3 = p\n    return x1 ** 2 + x2 ** 2 + x3 ** 2\n\n\nconstraint_eq = [\n    lambda x: 1 - x[1] - x[2]\n]\n\nconstraint_ueq = [\n    lambda x: 1 - x[0] * x[1],\n    lambda x: x[0] * x[1] - 5\n]\n\n```\n\n**步骤 2**：执行差分进化算法  \n-> 示例代码：[examples\u002Fdemo_de.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_de.py#L25)\n```python\nfrom sko.DE import DE\n\nde = DE(func=obj_func, n_dim=3, size_pop=50, max_iter=800, lb=[0, 0, 0], ub=[5, 5, 5],\n        constraint_eq=constraint_eq, constraint_ueq=constraint_ueq)\n\nbest_x, best_y = de.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n\n```\n\n## 2. 遗传算法 (Genetic Algorithm)\n\n**步骤 1**：定义你的问题  \n-> 示例代码：[examples\u002Fdemo_ga.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga.py#L1)\n```python\nimport numpy as np\n\n\ndef schaffer(p):\n    '''\n    This function has plenty of local minimum, with strong shocks\n    global minimum at (0,0) with value 0\n    https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FTest_functions_for_optimization\n    '''\n    x1, x2 = p\n    part1 = np.square(x1) - np.square(x2)\n    part2 = np.square(x1) + np.square(x2)\n    return 0.5 + (np.square(np.sin(part1)) - 0.5) \u002F np.square(1 + 0.001 * part2)\n\n\n```\n\n**步骤 2**：执行遗传算法  \n-> 示例代码：[examples\u002Fdemo_ga.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga.py#L16)\n```python\nfrom sko.GA import GA\n\nga = GA(func=schaffer, n_dim=2, size_pop=50, max_iter=800, prob_mut=0.001, lb=[-1, -1], ub=[1, 1], precision=1e-7)\nbest_x, best_y = ga.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n```\n\n-> 示例代码：[examples\u002Fdemo_ga.py#s3](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga.py#L22)\n```python\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\nY_history = pd.DataFrame(ga.all_history_Y)\nfig, ax = plt.subplots(2, 1)\nax[0].plot(Y_history.index, Y_history.values, '.', color='red')\nY_history.min(axis=1).cummin().plot(kind='line')\nplt.show()\n```\n\n![Figure_1-1](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_1981ff284b69.png)\n\n### 2.2 用于旅行商问题 (Travelling Salesman Problem) 的遗传算法\n只需导入 `GA_TSP`，它重载了 `crossover`（交叉）、`mutation`（变异）以解决 TSP 问题。\n\n**步骤 1**：定义你的问题。准备点的坐标和距离矩阵。  \n这里我随机生成数据作为演示：  \n-> 示例代码：[examples\u002Fdemo_ga_tsp.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_tsp.py#L1)\n```python\nimport numpy as np\nfrom scipy import spatial\nimport matplotlib.pyplot as plt\n\nnum_points = 50\n\npoints_coordinate = np.random.rand(num_points, 2)  # generate coordinate of points\ndistance_matrix = spatial.distance.cdist(points_coordinate, points_coordinate, metric='euclidean')\n\n\ndef cal_total_distance(routine):\n    '''The objective function. input routine, return total distance.\n    cal_total_distance(np.arange(num_points))\n    '''\n    num_points, = routine.shape\n    return sum([distance_matrix[routine[i % num_points], routine[(i + 1) % num_points]] for i in range(num_points)])\n\n\n```\n\n**步骤 2**：执行遗传算法  \n-> 示例代码：[examples\u002Fdemo_ga_tsp.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_tsp.py#L19)\n```python\n\nfrom sko.GA import GA_TSP\n\nga_tsp = GA_TSP(func=cal_total_distance, n_dim=num_points, size_pop=50, max_iter=500, prob_mut=1)\nbest_points, best_distance = ga_tsp.run()\n\n```\n\n**步骤 3**：绘制结果：  \n-> 示例代码：[examples\u002Fdemo_ga_tsp.py#s3](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ga_tsp.py#L26)\n```python\nfig, ax = plt.subplots(1, 2)\nbest_points_ = np.concatenate([best_points, [best_points[0]]])\nbest_points_coordinate = points_coordinate[best_points_, :]\nax[0].plot(best_points_coordinate[:, 0], best_points_coordinate[:, 1], 'o-r')\nax[1].plot(ga_tsp.generation_best_Y)\nplt.show()\n```\n\n![GA_TPS](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_98b1861ecd44.png)\n\n\n## 3. PSO(粒子群优化算法)\n\n### 3.1 PSO\n**步骤 1**：定义你的问题：  \n-> 示例代码：[examples\u002Fdemo_pso.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_pso.py#L1)\n```python\ndef demo_func(x):\n    x1, x2, x3 = x\n    return x1 ** 2 + (x2 - 0.05) ** 2 + x3 ** 2\n\n\n```\n\n**步骤 2**：执行 PSO  \n-> 示例代码：[examples\u002Fdemo_pso.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_pso.py#L6)\n```python\nfrom sko.PSO import PSO\n\npso = PSO(func=demo_func, n_dim=3, pop=40, max_iter=150, lb=[0, -1, 0.5], ub=[1, 1, 1], w=0.8, c1=0.5, c2=0.5)\npso.run()\nprint('best_x is ', pso.gbest_x, 'best_y is', pso.gbest_y)\n\n```\n\n**步骤 3**：绘制结果  \n-> 示例代码：[examples\u002Fdemo_pso.py#s3](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_pso.py#L13)\n```python\nimport matplotlib.pyplot as plt\n\nplt.plot(pso.gbest_y_hist)\nplt.show()\n```\n\n\n![PSO_TPS](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_01da90411fe1.png)\n\n### 3.2 带非线性约束的 PSO\n\n如果你需要非线性约束，例如 `(x[0] - 1) ** 2 + (x[1] - 0) ** 2 - 0.5 ** 2\u003C=0`  \n代码如下：\n```python\nconstraint_ueq = (\n    lambda x: (x[0] - 1) ** 2 + (x[1] - 0) ** 2 - 0.5 ** 2\n    ,\n)\npso = PSO(func=demo_func, n_dim=2, pop=40, max_iter=max_iter, lb=[-2, -2], ub=[2, 2]\n          , constraint_ueq=constraint_ueq)\n```\n\n注意，你可以添加多个非线性约束。只需将它们添加到 `constraint_ueq` 中。\n\n此外，我们还提供了一个动画：  \n![pso_ani](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_aae3067a4039.gif)  \n↑查看 [examples\u002Fdemo_pso_ani.py](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_pso_ani.py)\n\n\n## 4. SA(模拟退火算法)\n\n### 4.1 多变量函数模拟退火 (SA)\n**步骤 1**：定义你的问题  \n-> Demo code: [examples\u002Fdemo_sa.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_sa.py#L1)\n```python\ndemo_func = lambda x: x[0] ** 2 + (x[1] - 0.05) ** 2 + x[2] ** 2\n\n```\n**步骤 2**：执行模拟退火 (SA)  \n-> Demo code: [examples\u002Fdemo_sa.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_sa.py#L3)\n```python\nfrom sko.SA import SA\n\nsa = SA(func=demo_func, x0=[1, 1, 1], T_max=1, T_min=1e-9, L=300, max_stay_counter=150)\nbest_x, best_y = sa.run()\nprint('best_x:', best_x, 'best_y', best_y)\n\n```\n\n**步骤 3**：绘制结果  \n-> Demo code: [examples\u002Fdemo_sa.py#s3](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_sa.py#L10)\n```python\nimport matplotlib.pyplot as plt\nimport pandas as pd\n\nplt.plot(pd.DataFrame(sa.best_y_history).cummin(axis=0))\nplt.show()\n\n```\n![sa](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_97aa0f703d15.png)\n\n\n此外，scikit-opt 提供三种类型的模拟退火算法：Fast、Boltzmann、Cauchy。详见 [更多 SA](https:\u002F\u002Fscikit-opt.github.io\u002Fscikit-opt\u002F#\u002Fen\u002Fmore_sa)\n### 4.2 旅行商问题 (TSP) 的模拟退火 (SA)\n**步骤 1**：哦，是的，定义你的问题。这一步太无聊了，就不复制了。  \n\n**步骤 2**：为 TSP 执行 SA  \n-> Demo code: [examples\u002Fdemo_sa_tsp.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_sa_tsp.py#L21)\n```python\nfrom sko.SA import SA_TSP\n\nsa_tsp = SA_TSP(func=cal_total_distance, x0=range(num_points), T_max=100, T_min=1, L=10 * num_points)\n\nbest_points, best_distance = sa_tsp.run()\nprint(best_points, best_distance, cal_total_distance(best_points))\n```\n\n**步骤 3**：绘制结果  \n-> Demo code: [examples\u002Fdemo_sa_tsp.py#s3](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_sa_tsp.py#L28)\n```python\nfrom matplotlib.ticker import FormatStrFormatter\n\nfig, ax = plt.subplots(1, 2)\n\nbest_points_ = np.concatenate([best_points, [best_points[0]]])\nbest_points_coordinate = points_coordinate[best_points_, :]\nax[0].plot(sa_tsp.best_y_history)\nax[0].set_xlabel(\"Iteration\")\nax[0].set_ylabel(\"Distance\")\nax[1].plot(best_points_coordinate[:, 0], best_points_coordinate[:, 1],\n           marker='o', markerfacecolor='b', color='c', linestyle='-')\nax[1].xaxis.set_major_formatter(FormatStrFormatter('%.3f'))\nax[1].yaxis.set_major_formatter(FormatStrFormatter('%.3f'))\nax[1].set_xlabel(\"Longitude\")\nax[1].set_ylabel(\"Latitude\")\nplt.show()\n\n```\n![sa](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_73940b6b99a0.png)\n\n\n更多：绘制动画：  \n\n![sa](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_a3eb5c0e9d41.gif)  \n↑**查看 [examples\u002Fdemo_sa_tsp.py](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_sa_tsp.py)**\n\n\n\n\n## 5. 旅行商问题 (TSP) 的蚁群算法 (ACA)\n-> Demo code: [examples\u002Fdemo_aca_tsp.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_aca_tsp.py#L17)\n```python\nfrom sko.ACA import ACA_TSP\n\naca = ACA_TSP(func=cal_total_distance, n_dim=num_points,\n              size_pop=50, max_iter=200,\n              distance_matrix=distance_matrix)\n\nbest_x, best_y = aca.run()\n\n```\n\n![ACA](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_c368df1fdac3.png)\n\n\n## 6. 免疫算法 (IA)\n-> Demo code: [examples\u002Fdemo_ia.py#s2](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_ia.py#L6)\n```python\n\nfrom sko.IA import IA_TSP\n\nia_tsp = IA_TSP(func=cal_total_distance, n_dim=num_points, size_pop=500, max_iter=800, prob_mut=0.2,\n                T=0.7, alpha=0.95)\nbest_points, best_distance = ia_tsp.run()\nprint('best routine:', best_points, 'best_distance:', best_distance)\n\n```\n\n![IA](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_readme_30a9eabcd22e.png)\n\n## 7. 人工鱼群算法 (AFSA)\n-> Demo code: [examples\u002Fdemo_afsa.py#s1](https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fblob\u002Fmaster\u002Fexamples\u002Fdemo_afsa.py#L1)\n```python\ndef func(x):\n    x1, x2 = x\n    return 1 \u002F x1 ** 2 + x1 ** 2 + 1 \u002F x2 ** 2 + x2 ** 2\n\n\nfrom sko.AFSA import AFSA\n\nafsa = AFSA(func, n_dim=2, size_pop=50, max_iter=300,\n            max_try_num=100, step=0.5, visual=0.3,\n            q=0.98, delta=0.5)\nbest_x, best_y = afsa.run()\nprint(best_x, best_y)\n```\n\n# 使用 scikit-opt 的项目\n\n- [Yu, J., He, Y., Yan, Q., & Kang, X. (2021). SpecView: 基于奇异谱变换的恶意软件频谱可视化框架。IEEE Transactions on Information Forensics and Security, 16, 5093-5107.](https:\u002F\u002Fieeexplore.ieee.org\u002Fabstract\u002Fdocument\u002F9607026\u002F)\n- [Zhen, H., Zhai, H., Ma, W., Zhao, L., Weng, Y., Xu, Y., ... & He, X. (2021). 基于强化学习 (Reinforcement-learning) 的潮流最优解生成器的设计与测试。Energy Reports.](https:\u002F\u002Fwww.sciencedirect.com\u002Fscience\u002Farticle\u002Fpii\u002FS2352484721012737)\n- [Heinrich, K., Zschech, P., Janiesch, C., & Bonin, M. (2021). 过程数据属性至关重要：引入门控卷积神经网络 (GCNN) 和键值预测注意力网络 (KVP) 以进行深度学习的下一个事件预测。Decision Support Systems, 143, 113494.](https:\u002F\u002Fwww.sciencedirect.com\u002Fscience\u002Farticle\u002Fpii\u002FS016792362100004X)\n- [Tang, H. K., & Goh, S. K. (2021). 一种受易经哲学启发的新型非种群元启发式优化器 (Meta-heuristic Optimizer)。arXiv preprint arXiv:2104.08564.](https:\u002F\u002Farxiv.org\u002Fabs\u002F2104.08564)\n- [Wu, G., Li, L., Li, X., Chen, Y., Chen, Z., Qiao, B., ... & Xia, L. (2021). 基于图嵌入 (Graph embedding) 的实时社交事件匹配用于 EBSNs 推荐。World Wide Web, 1-22.](https:\u002F\u002Flink.springer.com\u002Farticle\u002F10.1007\u002Fs11280-021-00934-y)\n- [Pan, X., Zhang, Z., Zhang, H., Wen, Z., Ye, W., Yang, Y., ... & Zhao, X. (2021). 一种基于配备双损失函数的注意力机制 (Attention mechanism) 循环神经网络 (RNN) 的快速鲁棒混合气体识别与浓度检测算法。Sensors and Actuators B: Chemical, 342, 129982.](https:\u002F\u002Fwww.sciencedirect.com\u002Fscience\u002Farticle\u002Fabs\u002Fpii\u002FS0925400521005517)\n- [Castella Balcell, M. (2021). WindCrete 浮动式海上风力涡轮机的系泊系统 (Station keeping system) 优化。](https:\u002F\u002Fupcommons.upc.edu\u002Fhandle\u002F2117\u002F350262)\n- [Zhai, B., Wang, Y., Wang, W., & Wu, B. (2021). 雾况下高速公路路段的最优可变限速控制 (Variable Speed Limit Control) 策略。arXiv preprint arXiv:2107.14406.](https:\u002F\u002Farxiv.org\u002Fabs\u002F2107.14406)\n- [Yap, X. H. (2021). 局部线性数据上的多标签分类 (Multi-label classification)：应用于化学毒性预测。](https:\u002F\u002Fetd.ohiolink.edu\u002Fapexprod\u002Frws_olink\u002Fr\u002F1501\u002F10?clear=10&p10_accession_num=wright162901936395651)\n- [Gebhard, L. (2021). 利用蚁群优化 (Ant Colony Optimization) 进行低压电网 (Low-Voltage Grids) 扩展规划 Ausbauplanung von Niederspannungsnetzen mithilfe eines Ameisenalgorithmus。](https:\u002F\u002Fad-publications.cs.uni-freiburg.de\u002Ftheses\u002FMaster_Lukas_Gebhard_2021.pdf)\n- [Ma, X., Zhou, H., & Li, Z. (2021). 氢能与电力系统 (Power Systems) 之间相互依赖关系的优化设计。IEEE Transactions on Industry Applications.](https:\u002F\u002Fieeexplore.ieee.org\u002Fabstract\u002Fdocument\u002F9585654)\n- [de Curso, T. D. C. (2021). Johansen-Ledoit-Sornette 金融泡沫 (Financial Bubbles) 模型研究。](https:\u002F\u002Fd1wqtxts1xzle7.cloudfront.net\u002F67649721\u002FTCC_Thibor_Final-with-cover-page-v2.pdf?Expires=1639140872&Signature=LDZoVsAGO0mLMlVsQjnzpLlRhLyt5wdIDmBjm1yWog5bsx6apyRE9aHuwfnFnc96uvam573wiHMeV08QlK2vhRcQS1d0buenBT5fwoRuq6PTDoMsXmpBb-lGtu9ETiMb4sBYvcQb-X3C7Hh0Ec1FoJZ040gXJPWdAli3e1TdOcGrnOaBZMgNiYX6aKFIZaaXmiQeV3418~870bH4IOQXOapIE6-23lcOL-32T~FSjsOrENoLUkcosv6UHPourKgsRufAY-C2HBUWP36iJ7CoH0jSTo1e45dVgvqNDvsHz7tmeI~0UPGH-A8MWzQ9h2ElCbCN~UNQ8ycxOa4TUKfpCw__&Key-Pair-Id=APKAJLOHF5GGSLRBV4ZA)\n- [Wu, T., Liu, J., Liu, J., Huang, Z., Wu, H., Zhang, C., ... & Zhang, G. (2021). 一种基于人工智能 (AI) 的无人机 (UAV) 辅助无线传感器网络中年龄信息最优 (AoI) 轨迹规划新框架。IEEE Transactions on Wireless Communications.](https:\u002F\u002Fieeexplore.ieee.org\u002Fabstract\u002Fdocument\u002F9543607)\n- [Liu, H., Wen, Z., & Cai, W. (2021, August). FastPSO：面向 GPU 上高效群体智能 (Swarm Intelligence) 算法。In 50th International Conference on Parallel Processing (pp. 1-10).](https:\u002F\u002Fdl.acm.org\u002Fdoi\u002Fabs\u002F10.1145\u002F3472456.3472474)\n- [Mahbub, R. (2020). 解决旅行商问题 (TSP) 的算法与优化技术。](https:\u002F\u002Fraiyanmahbub.com\u002Fimages\u002FResearch_Paper.pdf)\n- [Li, J., Chen, T., Lim, K., Chen, L., Khan, S. A., Xie, J., & Wang, X. (2019). 深度学习 (Deep learning) 加速金纳米团簇合成。Advanced Intelligent Systems, 1(3), 1900029.](https:\u002F\u002Fonlinelibrary.wiley.com\u002Fdoi\u002Ffull\u002F10.1002\u002Faisy.201900029)","# scikit-opt 快速上手指南\n\n`scikit-opt` 是一个基于 Python 的群智能优化算法库，支持遗传算法、粒子群优化、模拟退火、蚁群算法等多种启发式算法。\n\n## 1. 环境准备\n\n- **操作系统**: Windows \u002F Linux \u002F macOS\n- **Python 版本**: >= 3.5\n- **核心依赖**: `numpy` (用于数值计算)\n- **可选依赖**: `matplotlib`, `pandas` (用于结果可视化)\n\n## 2. 安装步骤\n\n推荐使用国内镜像源以加快下载速度：\n\n```bash\npip install -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple scikit-opt\n```\n\n如需开发最新版本，可克隆源码安装：\n\n```bash\ngit clone git@github.com:guofei9987\u002Fscikit-opt.git\ncd scikit-opt\npip install .\n```\n\n## 3. 基本使用示例\n\n以下以 **遗传算法 (Genetic Algorithm)** 为例，演示如何求解目标函数最小值问题。\n\n### 第一步：定义目标函数\n\n```python\nimport numpy as np\n\n\ndef schaffer(p):\n    '''\n    This function has plenty of local minimum, with strong shocks\n    global minimum at (0,0) with value 0\n    https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FTest_functions_for_optimization\n    '''\n    x1, x2 = p\n    part1 = np.square(x1) - np.square(x2)\n    part2 = np.square(x1) + np.square(x2)\n    return 0.5 + (np.square(np.sin(part1)) - 0.5) \u002F np.square(1 + 0.001 * part2)\n```\n\n### 第二步：初始化并运行算法\n\n```python\nfrom sko.GA import GA\n\nga = GA(func=schaffer, n_dim=2, size_pop=50, max_iter=800, prob_mut=0.001, lb=[-1, -1], ub=[1, 1], precision=1e-7)\nbest_x, best_y = ga.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n```\n\n### 第三步：查看历史收敛曲线（可选）\n\n```python\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\nY_history = pd.DataFrame(ga.all_history_Y)\nfig, ax = plt.subplots(2, 1)\nax[0].plot(Y_history.index, Y_history.values, '.', color='red')\nY_history.min(axis=1).cummin().plot(kind='line')\nplt.show()\n```\n\n更多算法（如 PSO、DE、TSP 等）及高级用法请查阅 [官方文档](https:\u002F\u002Fscikit-opt.github.io\u002Fscikit-opt\u002F#\u002Fzh\u002F)。","某电商物流公司的算法团队正在解决每日数百个网点的配送路径规划难题，目标是最小化总行驶里程并满足严格的时效要求。\n\n### 没有 scikit-opt 时\n- 需从零实现遗传算法核心逻辑，包括编码、交叉和变异操作，开发周期长达两周。\n- 调试过程繁琐，难以平衡种群多样性与收敛速度，常陷入局部最优解而无法突破。\n- 面对载重限制和时间窗等多重约束，手动编写过滤逻辑容易引入隐蔽的 Bug。\n- 不同项目间算法复用率低，每次调整策略都要重新修改底层代码，维护成本高昂。\n\n### 使用 scikit-opt 后\n- 利用 `scikit-opt` 内置的 GA_TSP 类，仅需定义目标函数即可快速启动优化流程。\n- 通过 register 方法自定义选择算子，轻松应对复杂的业务约束条件而不破坏框架。\n- 内置多种智能算法可选，无需反复调参即可找到接近全局最优的路径方案。\n- 代码结构清晰，后续维护和新需求扩展变得异常简单，大幅降低人力投入与试错成本。\n\n`scikit-opt` 将复杂的组合优化问题转化为标准接口调用，显著提升了算法落地效率。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fguofei9987_scikit-opt_3b4d5cd2.png","guofei9987","郭飞","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fguofei9987_93866838.jpg",null,"Alibaba","China","me@guofei.site","http:\u002F\u002Fwww.guofei.site","https:\u002F\u002Fgithub.com\u002Fguofei9987",[85,89],{"name":86,"color":87,"percentage":88},"Python","#3572A5",99.5,{"name":90,"color":91,"percentage":92},"Shell","#89e051",0.5,6401,1093,"2026-04-05T09:58:32","MIT",1,"Windows, Linux, macOS","未说明",{"notes":101,"python":102,"dependencies":103},"GPU 计算功能正在开发中，预计 1.0.0 版本稳定；支持用户自定义算子（UDF）；提供向量化、多线程、多进程及缓存等多种加速方式",">=3.5",[104,105,106,107],"numpy","matplotlib","pandas","scipy",[13,15],[110,111,112,113,114,115,116,117,118,119,120,121,122],"genetic-algorithm","pso","particle-swarm-optimization","tsp","travelling-salesman-problem","simulated-annealing","ant-colony-algorithm","immune-algorithm","heuristic-algorithms","immune","artificial-intelligence","fish-swarms","optimization",6,"2026-03-27T02:49:30.150509","2026-04-06T05:17:57.670322",[127,132,137,141,146,151],{"id":128,"question_zh":129,"answer_zh":130,"source_url":131},2002,"如何处理优化中的约束条件？","建议尽量使用 `lb` 和 `ub`（变量下限和上限），这两个约束是嵌入在算子中的，非常有效。`constraint_eq` 和 `constraint_ueq` 仅作为补充措施，仅在数量较少时发挥作用。如果约束关系都是线性的，可以用线性代数方法（如消元法或矩阵初等变换），将自变量约束变成 `lb \u003C x \u003C ub` 这种形式。","https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fissues\u002F52",{"id":133,"question_zh":134,"answer_zh":135,"source_url":136},2003,"如何修改遗传算法的交叉概率？","可以通过 `ga.register` 方法注册算子并传入参数来调整。例如：`ga.register(operator_name='crossover', operator=crossover.crossover_2point_prob, crossover_prob=0.5)`。具体配置可参考官方示例代码 `demo_ga.py`。","https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fissues\u002F79",{"id":138,"question_zh":139,"answer_zh":140,"source_url":136},2004,"如何导出每一代的最优值？","该功能支持通过查看官方示例代码实现。请参考 `demo_ga.py` 文件了解如何记录并导出每一代的最优值信息。",{"id":142,"question_zh":143,"answer_zh":144,"source_url":145},2005,"遗传算法收敛后期为何会在两个极端值之间跳跃？","这是突变导致的正常现象。少数个体偶尔会发生基因突变（如二进制位翻转），导致对应的值从最大变到最小。当染色体长度较长且精度较高时，大部分基因突变影响小，但个别关键基因突变会导致较大跳跃。可以尝试设置 `prob_mut = 0` 来验证效果。","https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fissues\u002F109",{"id":147,"question_zh":148,"answer_zh":149,"source_url":150},2006,"并行模式与多进程模式的性能差异及建议是什么？","建议使用最新开发版代码，旧版本可能存在性能问题。测试数据显示 `vectorization mode`（向量化模式）通常最快，其次是 `parallel` 和 `multiprocess` 模式。请确保下载最新代码库并通过 `python setup.py install` 安装开发版以获得最佳性能。","https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fissues\u002F107",{"id":152,"question_zh":153,"answer_zh":154,"source_url":155},2007,"如何自定义车辆路径问题（VRP）等复杂约束问题？","可以复用目标函数（objective function）。对于不同算法（如模拟退火、蚁群优化），只需复用目标函数，可能需要进行一些适配性修改即可，无需完全重写整个框架。","https:\u002F\u002Fgithub.com\u002Fguofei9987\u002Fscikit-opt\u002Fissues\u002F26",[157,162,167,172,177,182,187,192,197,202,207,212,217,222,227,232,237,242,247,252],{"id":158,"version":159,"summary_zh":160,"released_at":161},101487,"v0.6.5","- Add a toolkit x2gray.\r\n- Add a crossover fuction #79 ","2021-06-28T12:45:52",{"id":163,"version":164,"summary_zh":165,"released_at":166},101488,"v0.6.3","- Add multiprocessing&multithreading","2021-03-27T15:31:11",{"id":168,"version":169,"summary_zh":170,"released_at":171},101489,"v0.6.2","- Surport 3 kinds of accelerate strategy ( vectorization, parallel, cached)\r\n- Surport class methods directly as the objective function","2021-03-13T12:53:52",{"id":173,"version":174,"summary_zh":175,"released_at":176},101490,"v0.6.1","1. PSO now support nonlinear unequal constraint\r\n2. Remove unbounded algorithm from PSO","2020-11-20T12:55:12",{"id":178,"version":179,"summary_zh":180,"released_at":181},101491,"v0.5.9","1. Add input&output parameters\r\n2. Bring all 7 algorithms into correspondence for parameters, as much as possible.","2020-08-29T08:09:35",{"id":183,"version":184,"summary_zh":185,"released_at":186},101492,"v0.5.8","- Fix a critical bug in AFSA\r\n- make up a doc to show parameters （only Chinese now, English is on the way）","2020-08-07T14:59:02",{"id":188,"version":189,"summary_zh":190,"released_at":191},101493,"v0.5.7","In previous version, GA has an integer mode, which uses penalty function. It makes a lot of misunderstand, and misusage.  \r\nThe integer mode is totally changed to a new algorithm in this version.\r\n#32 #37 #59","2020-06-08T16:43:30",{"id":193,"version":194,"summary_zh":195,"released_at":196},101494,"v0.5.6","Bug fixed #45 : input parameter in SA","2020-04-18T15:22:30",{"id":198,"version":199,"summary_zh":200,"released_at":201},101495,"v0.5.5","bug: #34 ASFS, ASFA, AFSA","2020-01-31T17:40:37",{"id":203,"version":204,"summary_zh":205,"released_at":206},101496,"v0.5.4","- Fix a vital bug about array copy in ACA\r\n- GA&PSO: objective function supports vectorization calculation\r\n","2019-12-26T12:24:24",{"id":208,"version":209,"summary_zh":210,"released_at":211},101497,"v0.5.3","Better GA for TSP","2019-12-23T18:46:55",{"id":213,"version":214,"summary_zh":215,"released_at":216},101498,"v0.5.2","integer programming for GA","2019-12-22T08:10:21",{"id":218,"version":219,"summary_zh":220,"released_at":221},101499,"v0.5.0","- Differential Evolution available\r\n- Algorithm with constraint available\r\n- Move operators to a path `operators`\r\n- Remove old-style register UDF","2019-12-02T09:30:18",{"id":223,"version":224,"summary_zh":225,"released_at":226},101500,"v0.3.5","- 3 types of Simulated Annealing: Fast, Boltzmann, Cauchy. \r\n- Now Simulated Annealing is nearly perfect\r\n- documents is more specific","2019-11-25T13:24:44",{"id":228,"version":229,"summary_zh":230,"released_at":231},101501,"v0.3.4","- Almost perfect: Simulated Annealing for TSP\r\n- New docs\r\n- 2 animations (PSO and SA)","2019-11-21T16:05:22",{"id":233,"version":234,"summary_zh":235,"released_at":236},101502,"v0.3.3","- PSO (Particle Swarm Optimization) with constraint\r\n- Faster GA operators\r\n- New documents framework","2019-11-19T02:38:18",{"id":238,"version":239,"summary_zh":240,"released_at":241},101503,"v0.3.2","$pip install scikit-opt\r\n\r\n- A new type of register\r\n- Provide some operators","2019-10-25T09:34:38",{"id":243,"version":244,"summary_zh":245,"released_at":246},101504,"v0.3.1","$pip install scikit-opt\r\n\r\n- add immune algorithm, artificial fish swarm algorithm\r\n- new operators for GA\r\n- new types of udf\r\n","2019-09-17T13:39:54",{"id":248,"version":249,"summary_zh":250,"released_at":251},101505,"v0.2.1","This is the first releases  \r\nSee [here](https:\u002F\u002Fpypi.org\u002Fmanage\u002Fproject\u002Fscikit-opt\u002Freleases\u002F)  \r\n$pip install scikit-opt","2019-09-07T15:10:58",{"id":253,"version":254,"summary_zh":250,"released_at":255},101506,"v0.1.1","2019-09-06T05:48:38"]