From 078f20eb38adde765e73f9019d371f9e1159ae80 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Sun, 8 Sep 2024 18:28:14 +0800 Subject: [PATCH] ready to publish code --- A/3/low_bound_cal.py | 4 +++- A/3/sufficiency_test.py | 4 ++-- A/4/seek_max.py | 2 -- A/4/testplot.py | 10 +++++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/A/3/low_bound_cal.py b/A/3/low_bound_cal.py index 7709c42..605664c 100644 --- a/A/3/low_bound_cal.py +++ b/A/3/low_bound_cal.py @@ -2,7 +2,7 @@ from dragon import * kBegPitch = 0.3 kEndPitch = 0.55 -kTotalSteps = 10000 +kTotalSteps = 250000 kStepPitch = (kEndPitch - kBegPitch) / kTotalSteps kParallelNum=24 tasks_list = [kBegPitch + kStepPitch * i for i in range(kTotalSteps)] @@ -19,6 +19,8 @@ def ProcessEntryPoint(arg): status = CheckCollision(status2blocks(dragen.CalcMoveList())) tmp_res[pitch]=status print(f"res={status}",file=logf) + if status == -1: + break with lock: # 添加锁保护对共享字典的操作 shared_dict.update(tmp_res) diff --git a/A/3/sufficiency_test.py b/A/3/sufficiency_test.py index b9a3bc4..b6a5dae 100644 --- a/A/3/sufficiency_test.py +++ b/A/3/sufficiency_test.py @@ -1,7 +1,7 @@ from dragon import * kBegPitch = 0.45033 kEndPitch = 0.45034 -kTotalSteps = 1000 +kTotalSteps = 10 kStepPitch = (kEndPitch - kBegPitch) / kTotalSteps kParallelNum=24 tasks_list = [kBegPitch + kStepPitch * i for i in range(kTotalSteps)] @@ -9,7 +9,7 @@ task_list_per_process=[tasks_list[i::kParallelNum] for i in range(kParallelNum)] kDeltaThetaBeg=0 kDeltaThetaEnd=5*2*3.1415926 -kStepDeltaTheta=(kDeltaThetaEnd-kDeltaThetaBeg)/100 +kStepDeltaTheta=(kDeltaThetaEnd-kDeltaThetaBeg)/10000 print(f"len(task_list_per_thread)={len(task_list_per_process)}",file=sys.stderr) def ProcessEntryPoint(arg): pitch_list, process_id, shared_dict, lock = arg diff --git a/A/4/seek_max.py b/A/4/seek_max.py index 0d3e738..07afc91 100644 --- a/A/4/seek_max.py +++ b/A/4/seek_max.py @@ -10,8 +10,6 @@ for i in np.arange(10, 20, 1/1000): tasks_list.append(i) for i in np.arange(12, 14.2, 1/10000): tasks_list.append(i) -for i in np.arange(13,13.2,1/100000): - tasks_list.append(i) for i in np.arange(13.085,13.095,1/1000000): tasks_list.append(i) task_list_per_process=[tasks_list[i::kParallelNum] for i in range(kParallelNum)] diff --git a/A/4/testplot.py b/A/4/testplot.py index 7d10286..884ae68 100644 --- a/A/4/testplot.py +++ b/A/4/testplot.py @@ -1,5 +1,6 @@ import matplotlib.pyplot as plt import numpy as np +import mpmath as mp kPitch = 1.7 kAlpha = kPitch / (2 * np.pi) @@ -8,7 +9,12 @@ kCriticalRadius = 4.5 theta_max = (kCriticalRadius) / kAlpha + 2 * 2 * np.pi kPlotingRadius = theta_max * kAlpha -kCriticalTheta = 2.86 / ((2 / 3) * kAlpha) +def f(x): + r=(1/3)*kAlpha*mp.sqrt(1+x**2) + phi=mp.atan(x) + L=mp.mpf("2.86") + return (r+3*r*mp.cos(mp.pi-2*phi)-L)**2+(3*r*mp.sin(mp.pi-2*phi))**2-L**2 +kCriticalTheta = float(mp.findroot(f, 15, solver='secant')) # 生成角度数组 theta = np.linspace(kCriticalTheta, theta_max, 1000) @@ -80,7 +86,5 @@ theta_grid = np.arctan2(Y, X) valid_points = r_grid <= kPlotingRadius ax.scatter(theta_grid[valid_points], r_grid[valid_points], color='grey', s=10) # 灰色小点 -plt.title("The Moving Path") - # 显示图像 plt.show()