Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Yumingyuan
algorithm_lab
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
algorithm_lab
/
johnson_rules.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
54 lines (54 loc) · 1.74 KB
master
Breadcrumbs
algorithm_lab
/
johnson_rules.py
Copy path
Top
File metadata and controls
Code
Blame
54 lines (54 loc) · 1.74 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
def takefirst(elem):
return elem[1]#返回在A上的执行时间
def takesecond(elem):
return elem[2]#返回在B上的执行时间
def calc_jobs_cost(jobs_a,jobs_b):
total_cost=0
temp_calc=0
for i in range(len(jobs_a)):
temp_calc+=jobs_a[i][1]
if temp_calc>total_cost:
total_cost=temp_calc
total_cost+=jobs_a[i][2]
for i in range(len(jobs_b)):
temp_calc+=jobs_b[i][1]
if temp_calc>total_cost:
total_cost=temp_calc
total_cost+=jobs_b[i][2]
print("cost:",total_cost)
def john_calc(job_nums,jobs):
jobs_a=[]
jobs_b=[]
for i in range(job_nums):
#如果i工件在A设备上工作时间小于在B设备上工作时间
if jobs[i][1]<jobs[i][2]:
#将这个job放入jobs_a,根据在A上的工作时间,越短越先进行
jobs_a.append(jobs[i])
#如果这个job在B上的工作时间大于在A上的工作时间
else:
#将这个job放入jobs_b,根据在B上的工作时间,越短越后进行
jobs_b.append(jobs[i])
#jobs_a按在A上工作时间增长的顺序排序
jobs_a.sort(key=takefirst)
#jobs_b按在B上工作时间增长的顺序排序
jobs_b.sort(key=takesecond)
#将jobs_b元素列表反转,方便正向输出
jobs_b.reverse()
print("jobs sequence:",end='')
#正序输出jobs_a
for i in range(len(jobs_a)):
print(jobs_a[i][0],end='')
print(",",end='')
#正序输出jobs_b
for i in range(len(jobs_b)):
print(jobs_b[i][0],end='')
if i!=len(jobs_b)-1:
print(",",end='')
print("")#换行
calc_jobs_cost(jobs_a,jobs_b)#调用计算花费函数
if __name__=="__main__":
#工作列表,第一个是作业编号,第二个是在A上的生产时间,第三个是在B上的生产时间
jobs=[(1,2,5),(2,4,2),(3,3,3),(4,9,1),(5,1,7)]
#算法调用
john_calc(len(jobs),jobs)
You can’t perform that action at this time.