結果

問題 No.453 製薬会社
ユーザー Yuki_UtaaiYuki_Utaai
提出日時 2018-06-01 19:44:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 3,213 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 11,196 KB
実行使用メモリ 9,252 KB
最終ジャッジ日時 2023-09-12 21:23:43
合計ジャッジ時間 1,555 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
9,032 KB
testcase_01 WA -
testcase_02 AC 45 ms
8,980 KB
testcase_03 AC 45 ms
9,172 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 45 ms
9,252 KB
testcase_07 AC 45 ms
9,112 KB
testcase_08 AC 45 ms
9,032 KB
testcase_09 AC 45 ms
9,164 KB
testcase_10 WA -
testcase_11 AC 45 ms
9,220 KB
testcase_12 AC 45 ms
9,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random

#--------粒 子 群 最 適 化------------------------------

#評価関数: z = 1000*x+2000*y
def criterion(x, y):
    stock_c=w-0.75*(x)-2/7*(y)
    stock_d=h-0.25*(x)-5/7*(y)
    z=1000*x+2000*y
    if stock_c<0 or stock_d<0 or x<0 or y<0:
        z=-z
    return z

#粒子の位置の更新を行う関数
def update_position(x, y, vx, vy):
    stock_c=w-0.75*(x+vx)-2/7*(y+vy)
    stock_d=h-0.25*(x+vx)-5/7*(y+vy)
    if stock_c<0 or stock_d<0 or x+vx<0 or y+vy<0:
        new_x = x
        new_y = y
    else:
        new_x = x + vx
        new_y = y + vy
    return new_x, new_y

#粒子の速度の更新を行う関数
def update_velocity(x, y, vx, vy, p, g, w=0.5, ro_max=1, c1=2.05, c2=2.05):
    #パラメーターroはランダムに与える
    ro1 = random.uniform(0, ro_max)
    ro2 = random.uniform(0, ro_max)
    phi=c1+c2
    K=2/abs(2-phi-(phi*phi-4*phi)**0.5)
    #粒子速度の更新を行う
    new_vx =K * ( w * vx + c1 * ro1 * (p[0] - x) + c2 * ro2 * (g[0] - x) )
    new_vy =K * ( w * vy + c1 * ro1 * (p[1] - y) + c2 * ro2 * (g[1] - y) )

#    new_vx = w * vx + ro1 * (p[0] - x) + ro2 * (g[0] - x)
#    new_vy = w * vy + ro1 * (p[1] - y) + ro2 * (g[1] - y)
    return new_vx, new_vy

def main():
    N = 100  #粒子の数
    x_min, x_max = 0, 2*w
    y_min, y_max = 0, 2*h
    #粒子位置, 速度, パーソナルベスト, グローバルベストの初期化を行う
    ps = [[random.uniform(x_min, 0.7*w), random.uniform(y_min, 0.7*h)] for i in range(N)]
    vs = [[0.0, 0.0] for i in range(N)]

    personal_best_positions = list(ps)
    personal_best_scores = [criterion(p[0], p[1]) for p in ps]
    best_particle = personal_best_scores.index(max(personal_best_scores))
    global_best_position = personal_best_positions[best_particle]



    T = 100  #世代数(ループの回数)
    for t in range(T):
        for n in range(N):
            x, y = ps[n][0], ps[n][1]
            vx, vy = vs[n][0], vs[n][1]
            p = personal_best_positions[n]

            #粒子の位置の更新を行う
            new_x, new_y = update_position(x, y, vx, vy)
            ps[n] = [new_x, new_y]

            #粒子の速度の更新を行う
            new_vx, new_vy = update_velocity(new_x, new_y, vx, vy, p, global_best_position)
            vs[n] = [new_vx, new_vy]

            #評価値を求め, パーソナルベストの更新を行う
            score = criterion(new_x, new_y)
            if score > personal_best_scores[n]:
                personal_best_scores[n] = score
                personal_best_positions[n] = [new_x, new_y]

        #グローバルベストの更新を行う
#        f.write(str(max(personal_best_scores))+"\n")
        best_particle = personal_best_scores.index(max(personal_best_scores))
        global_best_position = personal_best_positions[best_particle]


    #最適解

#    print(max(personal_best_scores))#, global_best_position)
    return max(personal_best_scores)
#--------------------------------------------------------------

w, h=[int(i) for i in input().split()]
best=0
for i in range(1):
#  with open('result.txt', 'w') as f:
    best=max(best, main())
#    print(best)
print(best)
0