Files
2026_DesignAI/dofile/examples/README.md
T
2026-05-29 18:07:06 +08:00

180 lines
4.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 可运行代码示例
本目录包含书中提到的所有可运行代码示例,按章节组织。
## 目录结构
## 测试
```
examples/
├── 00-introduction/ # 导论部分示例
│ └── setup-first-assistant/ # 第一个空间AI助手
├── 01-foundations/ # 基础原理示例
│ ├── modular-system/ # 模块化系统
│ ├── state-machine/ # 状态机实现
│ ├── probability/ # 概率与不确定性
│ ├── feedback/ # 反馈与学习
│ └── hitl/ # 人机协同
├── 02-spatial-intelligence/ # 空间智能示例
│ ├── spatial-representation/ # 空间表征
│ ├── spatial-reasoning/ # 空间推理
│ ├── mcdm/ # 多准则决策
│ ├── optimization/ # 空间优化
│ └── uncertainty/ # 不确定性量化
├── 03-autonomous-design/ # 自主设计示例
│ ├── workflow/ # 工作流编排
│ ├── agents/ # Agent设计
│ ├── skills/ # 技能组合
│ └── memory/ # 记忆管理
└── templates/ # 项目模板
├── basic-skill.md
├── langgraph-workflow.py
└── hitl-checkpoint.py
```
## 快速开始
### 环境配置
```bash
# 克隆仓库
git clone https://github.com/your-org/CC4SI.git
cd CC4SI
# 创建虚拟环境
python -m venv venv
source venv/bin/activate # Linux/Mac
# 或
venv\Scripts\activate # Windows
# 安装依赖
pip install -r requirements.txt
```
### 运行示例
```bash
# 导论示例:第一个空间助手
python 00-introduction/setup-first-assistant/spatial_helper.py
# 基础原理示例:状态机
python 01-foundations/state-machine/workflow_state_machine.py
# 空间智能示例:空间推理
python 02-spatial-intelligence/spatial-reasoning/corridor_detection.py
```
## 示例说明
### 00-introduction/setup-first-assistant
**目标**:搭建第一个空间AI助手
**内容**
- `spatial_helper.py` - 空间分析助手类
- `create_sample_data.py` - 创建示例数据
- `README.md` - 使用说明
**运行**
```bash
cd 00-introduction/setup-first-assistant
python spatial_helper.py
```
---
### 01-foundations/modular-system
**目标**:理解模块化系统设计
**内容**
- `pipeline.py` - 空间分析流水线
- `skills.py` - 技能封装示例
- `composition.py` - 函数式组合
---
### 01-foundations/state-machine
**目标**:实现状态机工作流
**内容**
- `workflow_state_machine.py` - 完整状态机实现
- `langgraph_example.py` - LangGraph版本
---
### 02-spatial-intelligence/mcdm
**目标**:多准则决策分析
**内容**
- `ahp.py` - 层次分析法
- `sensitivity.py` - 敏感性分析
- `weighted_overlay.py` - 加权叠加
---
### 03-autonomous-design/workflow
**目标**:工作流编排实践
**内容**
- `dag_workflow.py` - DAG工作流
- `conditional_routing.py` - 条件路由
- `error_handling.py` - 错误处理模式
---
## 依赖要求
```
python>=3.10
# 核心依赖
geopandas>=0.13.0
shapely>=2.0.0
rasterio>=1.3.0
networkx>=3.0
# AI框架
langchain>=0.1.0
langgraph>=0.0.20
anthropic>=0.18.0
# 可视化
matplotlib>=3.7.0
folium>=0.14.0
# 数据处理
pandas>=2.0.0
numpy>=1.24.0
# 科学计算
scipy>=1.10.0
scikit-learn>=1.3.0
```
## 使用建议
1. **边学边做**:阅读相关章节后立即运行对应示例
2. **修改实验**:在理解代码基础上进行修改和实验
3. **错误调试**:遇到错误时尝试独立解决,培养调试能力
4. **记录笔记**:在代码注释或笔记本中记录你的理解
## 贡献示例
欢迎贡献更多示例!
**示例质量要求**
1. 代码可运行
2. 有清晰注释
3. 包含使用说明
4. 说明设计意图
详见 [CONTRIBUTING.md](../CONTRIBUTING.md)
## 许可
所有示例代码遵循项目许可证:CC BY-NC-SA 4.0