Stable-Matching

本文探讨了PSL公司如何通过算法确保所有船只在不同港口进行维修而不违反安全规定,详细介绍了算法流程、正确性证明及时间复杂度分析。

一. 匹配问题

PSL is a shipping company that owns n ships and provides service to n ports.Each ship has a schedule that says, for each day of the month (m(m > n) days),  which of the ports it's currently visiting, or whether 

it'out at sea. Each ship visits each port for exactly one day during the month. For safety reasons, PSL has

the following strict requirement:

(£) No two ships can be in the same port on the same day.

The company wants to perform maintenance on all the ships this month.   In this case, each ship Si will

arrive in one scheduled port and simply remains there for the rest of the month (for maintenance). 

This means that Si will not visit the remaining ports on its schedule (if any) that month.

Now the question is: given the schedule for each ship, find when each ship should stop its travel so 

that condition (£) continues to hold. Try to give an algorithm to find the solution and analyse its time 

complexity.


For example, there are 2 ships and 2 ports, and 4 days in this “month”.

If the schedule of the first ship is:

port P1 ; at sea; port P2 ; at sea

and the schedule of the second ship is:

at sea; port P1; at sea; port P2

then the only solution is to make the first ship stay in port P2 since the

third day, and the second ship stay in port P1 since the second day.


二.问题分析:

首先给了一个各个Ship的schedule表格,安排每个船的靠岸航海情况,并且要进行维修,就是给每个Ship找一个Port, 就是进行匹配的问题。

 

问题解决:

这个问题应用Gale-Shapley 算法,但稍微有些区别,将Ship 比作Man, Port 比作 Women,只是women没有了选择的权利,但是有day 的限制,  并且Ship后到Port的将有更多的权利可以占有这个Port。且每个Port不能同时有两个ship, 即对应的不能两个men,求婚成功同一个women。

维修匹配算法流程:

<pre name="code" class="cpp">for d = 1 to N do
	day[d] = 0;
end for;
while TRUE do
	If there is no ship s such that state[s] = NULL then
       return;
	end if
	select such a ship s arbitrarily;
	p = the next port on s’s schedule to whom s have not yet arrived;
	if state[p] == NULL then
		state[p] = s; state[s] = p;
	else if the ship arrive the port day[s] > the state[p] arrive the port day[state[p]] then
		state[state[p]] = NULL; state[p] = s; state[s] = p;
	else  
		;//do nothing means simply find next port;
	end if
end while


三.正确性证明:

 1)在海上的ship就会寻找下个schedule 上的port,只要日期在当前已有ship后面就可停靠。

 2)每个port 只要有ship, 就会一直保持有ship。

 3)一个ship 停在了一个port, 还有可能被其他船占用。

 

可结束:

假设有个port没有ship, 则一定有个ship 并且已将停过此port 在sea 上,则它一定被替代了,或者还没有到这个port, 与算法流程不符。

 

时间复杂度:

与Gale-Shapley 算法一样是O(n^2) 。




### 关于Stable Diffusion WebUI资产的相关资源和教程 #### Stable Diffusion WebUI简介 Stable Diffusion WebUI 是一种基于浏览器的界面工具,用于简化生成式人工智能模型的操作流程。它允许用户通过图形化界面调整参数并运行复杂的机器学习任务,而无需深入掌握编程技能[^3]。 #### 资源推荐 以下是几个常用的资源链接以及说明: 1. **官方文档与GitHub仓库** 官方GitHub页面提供了详细的安装指南、配置方法以及常见问题解答。这是获取最新版本和支持的最佳起点。 - GitHub地址: https://github.com/AUTOMATIC1111/stable-diffusion-webui 2. **社区论坛与讨论组** 社区支持对于解决特定问题是不可或缺的一部分。Reddit 和 Discord 上都有活跃的开发者群体分享经验和技术细节。 3. **YouTube 教程视频** 许多创作者制作了关于如何设置环境变量、优化性能以及自定义脚本功能的教学视频。这些多媒体资料非常适合初学者快速入门。 ```bash # Example command to clone the repository git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git ``` 4. **扩展插件生态系统** 插件可以显著增强WebUI的功能范围。例如,“ControlNet”插件能够实现图像到图像转换等功能;“Deforumation”则专注于动画创作领域内的应用探索[^4]。 #### 技术要点解析 - **模型加载机制**: 用户可以通过指定路径来加载预训练权重文件(.ckpt/.safetensors),从而切换不同风格的艺术作品生成模式[^5]。 - **批量处理能力**: 支持一次性渲染多个图片序列,在艺术设计项目中有广泛用途[^6]. ```python from modules import sd_models def load_model(model_name): """Load a specific model by name.""" info = sd_models.get_closet_checkpoint_match(model_name) if not info: raise ValueError(f"No checkpoint found matching {model_name}") sd_models.load_model(info.filename) load_model('v1-inpainting-fp16') ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值