2017-10-18 4 views
0

私はRandomStrategySelection次のコード関数で生成された変数(リスト)を次の関数の入力として使用する方法は?

# Random Strategy Selection: ramdomly choose a strategy within each player's strategy profile for each game in the input list 

def RandomStrategySelection(): # Return the vectors with the selected 
    P = pool_of_games 
    j=10 #number of iterations 
    s=1 #current round 
    random_strategy=[] #combination of randomly chosen strategies for each player 
    random_pool=[] #pool of selected random strategies for the input vector games 
    rp=random_pool 
    while s<=j: 
     for game in range (0, len(P)):  
      p1=random.choice(P[game][0][0:3]) #random choice within p1(row)'s strategy profile 
      p2=random.choice(P[game][0][4:8]) #random choice within p2(column)'s strategy profile 
      random_strategy=[p1,p2] 
      random_pool.append(random_strategy) 
     s=s+1 
    return(rp) 

def FitnessEvaluation():   # Return the rank of fitness of all evaluated games 
    for game in range (0,len(rp)): 
     pf1=rp[game][0] 
     pf2=rp[game][1] 
     fitness=payoff1+payoff2 
    return(fitness) 


    #fitness: f(G)=(F(G)*j+s)/j - F(G)=pf1+pf2 

を持っているが、このような

[[0,2][3,1]] 

として、オブジェクトのリストを生成しFitnessEvaluationは、そのリストを使用することになっているが、私はそれを実行します傾けます。 FitnessEvaluationは、rp変数に格納した後でも、作成されたリストを認識していないようです。何かご意見は?ありがとう!

答えて

0

ローカルrp変数に保存しました。これはローカルrpの変数RandomStrategySelectionとは異なります。

pool = RandomStrategySelection() 
how_fit = FitnessEvaluation(pool) 

...第2の機能に署名を与える:

これを処理する標準的な方法は、(呼び出し側のプログラムに)戻り値を保存し、次のいずれかにそれを渡す、といったことです

FitnessEvaluation(rp): 
    for game in range (0,len(rp)): 
     .... 
+0

この場合、最初の関数のhow_fitは「割り当てられたことはありません」とみなされます。後でそれをどこに追加する予定ですか? – vferraz

+0

呼び出し元プログラムによって異なります。 **最終的な結果は** FitnessEvaluation **の形式で返されますか?あなたは[最小、完全で、検証可能な例](http://stackoverflow.com/help/mcve)を提供していないので、私はそれで何をするのかを説明するセマンティクスは持っていません。 – Prune

関連する問題