Python项目:The Ship Rendezvous Problem,利用贪心算法解决船舶交会问题

2023-11-10

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


1 Introduction

该项目是Msc授课型研究生作业,课程代码:MATH6005-33055-21-22,具有一定挑战性。

Your company has been contracted to provide a tool in Python to solve the Ship Rendezvous problem (SRP) to enable a cruise company to minimize the time it takes for the support ship to visit each of the cruise ships in the fleet.
The support ship must visit each of the n cruise ships exactly once and then return to the port (where it started). The support ship travels at a constant speed and changes direction with negligible time. Each cruise ship moves at a constant velocity (i.e. Speed and direction). The objective is to minimize the total time taken to visit all the cruise ships (i.e. The time taken to reach the final ship).
This problem is considered in 2-dimensional (2D) Euclidean space. A problem instance is defined by specifying the starting (x, y) coordinates for all ships (including the support ship), the velocity of the support ship, and the velocity of the cruise ships.
Note that it is certain that the SRP has a finite solution if the support ship is faster than all other ships in the fleet. However, it is very likely (but not certain) that the SRP will not have a complete solution (one where all the cruise ships are visited) if one or more of the cruise ships are faster than the support ship.


2 Python Task

You must implement the greedy heuristic for the 2D Euclidean SRP in Python. Your program must perform the following tasks:
• Read the data from a CSV file (a sample data file is provided on Blackboard sample_srp_data.csv);
• Run the greedy heuristic against the problem instance to obtain a solution;
• Output a list of indexes of unvisited cruise ships, a list of indexes of the visited cruise ships, and the total time to visit all visitable cruise ships.

Greedy Heuristic for the SRP

A simple way of finding a solution to the SRP is to use a greedy heuristic. The greedy heuristic
works as follows

  1. For each unvisited cruise ship, calculate how long it would take the support ship to intercept it from the support ship’s current position.
  2. Choose the cruise ship, i, which can be reached in the shortest amount of time.
  3. Visit cruise ship i and update the positions of the ships in the fleet.
  4. Return to 1 if there are any unvisited cruise ships that can be reached by the support ship.
    In order to make the heuristic deterministic (i.e. to guarantee the same result each time it is run on the same problem instance) you must specify how ties in Step 2 are broken. If there is a tie, the algorithm should choose to visit the ship with the smallest index (for example, if ships 5 and 7 are tied, ship 5 should be chosen in preference to ship 7).
    The Technical Appendix (at the end of this document) provides details on how to calculate intercept times.

Function prototypes

代码如下(示例):

import pandas as pd
def read_srp_input_data(csv_file):
	’’’
	function description
	’’’
	input_data =pd.read_csv(csv_file)
	return input_data

The function must use the input variable csv_file to read the TXT file, inside of the function. You cannot use a fixed path file. If the function does not read the file using the input variable csv_file no partial credit will be given


def findPath (input_data):
	’’’
	function description
	’’’
	unvisited_index = [] # It must be a LIST. It cannot be a tuple nor NumPy array.
	visited_path = [] # It must be a LIST. It cannot be a tuple nor NumPy array.
	total_time = 0 # it must be a float.
	return unvisited_index, visited_path, total_time


The function outputs must be in the order as specified on the prototype. If the function outputs are not in the set order no partial credit will be given.

Example

There are 5 cruise ships on the fleet. Suppose that, using the Greedy Heuristic, the support ship can only visit 3 of them with the indexes 1, 2, 4 (e.g. the 2 remained cruise ships with the indexes 3, 5 cannot be visited). Remember that support ship should have index “0” and the first cruise ship has index “1” and so on. Then an example for a solution looks like:

[3 , 5], [2 ,4 ,1], 45.3

which mean that unvisited_index = [3,5], visited_path = [2,4,1] and total_time = 45.3. The visited_path = [2,4,1] means that the support ship will visit the cruise ship with index 2 first, and then the cruise ship with index 4, and finally the cruise ship with index 1.

3 Advice on writing the code

Make sure you follow the guidelines below when writing your code:
• You can (and are encouraged to) create new functions if needed. These must follow the good coding practices we have taught in the lectures and labs. However, your submission must include all the functions provided in the template, with the exact same names provided in the template.
• Your code should implement exactly the algorithm described above. Do not use an alternative. If you use a different algorithm (even if the algorithm solves the problem correctly and the results seem better) your assignment will be marked as incorrect.
• We will test your code against an unseen set of problem instances. We recommend that you test your algorithm and make sure that your code returns the expected solutions for different scenarios. To help you do this, you may create and test new CSV files for which you think you know the expected behaviour.
• We will only use correct input CSV files to test your code. The assignment does not ask you to include logic to handle non-numeric or incorrect CSV files. There are no extra marks available for including this functionality.

4 Technical Appendix

This appendix contains some technical information to help you solve the proposed problem in the assignment. Please, pay attention to these formula and specifications to ensure that your algorithm produces the correct results.

Notation

We denote the starting coordinates of the support ship by (X0; Y0) and its speed by S. We consider the ship i in the task force, where 1 ≤ i ≤ n. We denote its starting coordinates by (xi0; yi0). Its velocity is split into x-component and y-component, vix and viy , respectively. Therefore the
position of ship i at time t > 0 is given by
在这里插入图片描述
Note that the speed of ship i (denoted by si) can be obtained from its velocity with the following equation:
在这里插入图片描述

Calculating intercept times

To calculate intercept times, it is simplest to update the position of the ships at every step, so that (X0; Y0) represents the current coordinates of the support ship and (xi0; yi0) represents the current coordinates of ship i for 1 ≤ i ≤ n. Then the time, T, taken for the support ship to move from its current position and intercept ship i is found by finding the smallest positive root of the quadratic equation:
在这里插入图片描述
where the coefficients are obtained as follows:
在这里插入图片描述
Input Data
The input data for each problem instance will be presented in a comma separated value (CSV) file. A correctly-formatted input file consists of N rows of data, where N ≥ 2. Row 1 corresponds to the support ship, and the remaining rows (i.e. rows 2; …; N) correspond to the ships to be
intercepted. Each row contains five pieces of information in the following order:
• Ship name/description (text).
• Start x-coordinate (decimal number).
• Start y-coordinate (decimal number).
• Velocity x-component (decimal number).
• Velocity y-component (decimal number).

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python项目:The Ship Rendezvous Problem,利用贪心算法解决船舶交会问题 的相关文章

随机推荐

  • C# WPF Border控件总结

    Border控件不是一个布局面板 而是一个非常便于使用的元素 经常与布局面板一起使用 所以 在继续介绍其他布局面板之前 现在先介绍一下Border控件是有意义的 Border类非常简单 它只能包含一段嵌套内容 通常是布局面板 并为其添加背景
  • 元宇宙商标的致富路,断了

    链新 ID ChinaBlockchainNews 原创作者 杨郑君 2021年被称之为 元宇宙元年 也迎来了元宇宙商标注册的热潮 2021年全年 注册的元宇宙商标数量占目前元宇宙商标总数的99 9 然而 热潮背后却是疯狂抢注的乱象 腾讯
  • 安装cuda驱动

    目录 1 查看电脑上cuda版本 2 输入命令 查看cuda版本 3 去官网下载驱动 3 1 选择对应版本 3 2 选择下载版本 4 下载完成后 双击运行 4 1 同意许可协议 4 2 自定义 4 3 安装 5 输入命令验证 1 查看电脑上
  • C++机器学习库整理

    来自谷歌AI的TensorFlow 由 Google 开发的热门深度学习库 它拥有自己的工具 库和社区资源生态系统 使研究人员和开发人员能够轻松构建和部署 ML 支持的应用程序 官方文档 https www tensorflow org l
  • winform制作音乐播放器

    winform制作音乐播放器 本文利用C 调用Windows自带的Windows Media Player 打造一款属于自己的音乐播放器 以供学习分享使用 如有不足之处 还请指正 概述 Windows Media Player是微软公司出品
  • 4.3 服务器上的 Git - 生成 SSH 公钥

    4 3 服务器上的 Git 生成 SSH 公钥 版本说明 版本 作者 日期 备注 0 1 loon 2019 3 25 初稿 目录 文章目录 4 3 服务器上的 Git 生成 SSH 公钥 版本说明 目录 生成 SSH 公钥 生成 SSH
  • SVN 在文件比较时提示:is not a avlid text file!

    解决方法 将文件编码格式改为 在VS中有File gt Save Advance Option
  • 【Springboot】——@EnableAsync@Async

    一直不太明白 线程池在实际应用当中到底扮演什么样的角色 有什么场景要用到 只有真正的项目设计的时候才能逐渐理解 实践出真知说的就是这么个道理 使用多线程 往往是创建Thread 或者是实现runnable接口 用到线程池的时候还需要创建Ex
  • [ Android实战 ] 通过uri删除文件

    Android通过 uri 删除文件 通过 file 开头的 uri 删除文件 通过 content 开头的 uri 删除文件 通过 ContentResolver delete 删除文件 通过 DocumentFile fromSingl
  • 硬核科普:一片晶圆可以生产多少芯片?

    视频来源 腾讯视频 原视频 52赫兹 点击查看往期内容 关注芯片之家 往期好文阅读 芯片之家精选文章合集 一 收藏起来慢慢看 芯片之家精选文章合集 二 收藏起来慢慢看 点击阅读
  • ios 卡顿,push多次同一个页面

    场景 快速多次点击cell跳转到另一个页面 另一个页面被push多次 原因 push后的页面有耗时操作或者刚好push到另一个页面时 另一个页面正好在reloadData卡住主线程 造成点击cell时卡住了 解决方法 重写导航控制器的pus
  • 如何通过SSH连接阿里云上的Linux系统

    亲测可用 若有疑问请私信 首先SSH是啥 维基一下 Secure Shell 安全外壳协议 简称SSH 是一种加密的网络传输协议 可在不安全的网络中为网络服务提供安全的传输环境 1 SSH通过在网络中创建安全隧道来实现SSH客户端与服务器之
  • 01、win10下Apache 2.4.29+PHP 7.2.3+MySQL 5.7.21免安装开发环境配置

    一 软件下载 Apache2 4 29下载 下载地址 下载教程 PHP7 2 3下载 下载地址 下载教程 注意 一定要下载php 5 5 thread safe版本的 不然在后边没有要用到的php5apache2 4 dll库 MySQL5
  • android知识点 020 —— 版本信息,Android.os.Build 常用类

    1 Build VERSION SDK INT 软件app安装在哪个手机上 该手机的操作系统版本号 比如8 1对应的SDK INT是27 The SDK version of the software currently running o
  • qt案例-播放暂停动图

    wigdet h ifndef WIDGET H define WIDGET H include
  • MAC 查看程序安装目录

    查看程序安装目录 ps ef grep 程序名字 e g ps ef grep matlab
  • python中math库最大值_Python之math库和random库

    import math 相关函数 math ceil x x向上取最近的整数 然后返回这个整数 例 ceil 2 1 3 math degrees x 将x从弧度转换成角度 math fabs x 将x看作一个浮点数 返回它的绝对值 例 f
  • memcach基础知识--1

    memcache 1 memcache数据访问模型 首次访问从数据库查询 这是memcache 的模型 我们可以通过整合spring 来实现自己的数据同步机制 2 memcache 是相互之间乎不通信的分布式 memcache的分布式是完全
  • 电脑的任务栏卡,但是桌面可以正常使用

    这个的任务栏卡的原因可能如下 1 电脑后台运行过多的任务 占用过多c盘资源 导致任务栏卡死 解决方法 关掉多余的任务栏 2 也有可能是因为自己的windows更新 更新之后 任务栏 gt 右键 gt 资讯与兴趣 因为这个资讯与兴趣导致的任务
  • Python项目:The Ship Rendezvous Problem,利用贪心算法解决船舶交会问题

    提示 文章写完后 目录可以自动生成 如何生成可参考右边的帮助文档 Python利用贪心算法解决船舶交会问题 1 Introduction 2 Python Task Greedy Heuristic for the SRP Function