solfunc.cc

来自「Gambit 是一个游戏库理论软件」· CC 代码 · 共 688 行 · 第 1/2 页

CC
688
字号
//// $Source: /home/gambit/CVS/gambit/sources/gcl/solfunc.cc,v $// $Date: 2002/09/10 14:27:35 $// $Revision: 1.6.2.1 $//// DESCRIPTION:// GCL functions on profiles and solutions//// This file is part of Gambit// Copyright (c) 2002, The Gambit Project//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//#include "gsm.h"#include "portion.h"#include "gsmfunc.h"#include "game/efg.h"#include "game/nfg.h"#include "nash/behavsol.h"#include "nash/mixedsol.h"#include "game/nfplayer.h"#include "game/efgutils.h"//// Implementations of these are provided as necessary in gsmutils.cc//template <class T> Portion *ArrayToList(const gArray<T> &);// these added to get around g++ 2.7.2 not properly completing type// unification when gVector passed to the parameter...extern Portion *ArrayToList(const gArray<double> &);extern Portion *ArrayToList(const gArray<gRational> &);extern Portion *ArrayToList(const gArray<gNumber> &);template <class T> Portion *ArrayToList(const gList<T> &);template <class T> Portion *gDPVectorToList(const gDPVector<T> &);//----------------// ActionProb//----------------static Portion *GSM_ActionProb(GSM &, Portion **param){  const BehavSolution *profile = ((BehavPortion *) param[0])->Value();  Action* action = ((ActionPortion*) param[1])->Value();  Infoset* infoset = action->BelongsTo();  EFPlayer* player = infoset->GetPlayer();    if (player->IsChance())    //    return new NumberPortion(infoset->Game()->GetChanceProb(infoset, action->GetNumber()));    return new NumberPortion(profile->ActionProb(action));  else if (profile->Support().Find(action))    //    return new NumberPortion((*profile)(action));    return new NumberPortion(profile->ActionProb(action));  else    return new NumberPortion(0.0);}//------------------// ActionValue//------------------static Portion *GSM_ActionValue(GSM &, Portion **param){  BehavSolution *profile = ((BehavPortion *) param[0])->Value();  Action* action = ((ActionPortion*) param[1])->Value();  Infoset *infoset = action->BelongsTo();  if (infoset->GetPlayer()->IsChance())    return new NullPortion(porNUMBER);  else if (profile->Support().Find(action))  {    if(profile->IsetProb(infoset)>gNumber(0.0))      return new NumberPortion(profile->ActionValue(action));    else      return new NullPortion(porNUMBER);  }  else    return new NullPortion(porNUMBER);}//--------------// Behav//--------------static Portion *GSM_Behav(GSM &, Portion **param){  EFSupport *S = ((EfSupportPortion *) param[0])->Value();  return new BehavPortion(new BehavSolution(BehavProfile<gNumber>(*S)));}//-------------// Belief//-------------static Portion *GSM_Belief(GSM &, Portion **param){  BehavSolution *bp = ((BehavPortion *) param[0])->Value();  Node* n = ((NodePortion*) param[1])->Value();  Infoset *s = n->GetInfoset();  if(!s)    return new NullPortion(porNUMBER);  return new NumberPortion(bp->BeliefProb(n));}//-------// Game//-------static Portion* GSM_Game_Mixed(GSM &, Portion** param){  return new NfgPortion(&((MixedPortion *) param[0])->Value()->Game());}static Portion *GSM_Game_NfSupport(GSM &, Portion **param){  Nfg *N = (Nfg *) &((NfSupportPortion *) param[0])->Value()->Game();  return new NfgPortion(N);}static Portion* GSM_Game_EfgTypes(GSM &, Portion** param){  if(param[0]->Game())  {    assert(param[0]->GameIsEfg());    return new EfgPortion((efgGame*) param[0]->Game());  }  else    return 0;}//---------------// Creator//---------------static Portion *GSM_Creator_Behav(GSM &, Portion** param){  BehavSolution *bs = ((BehavPortion*) param[0])->Value();  return new TextPortion(bs->Creator());}static Portion *GSM_Creator_Mixed(GSM &, Portion** param){  MixedSolution *ms = ((MixedPortion*) param[0])->Value();  return new TextPortion(ms->Creator());}//---------------// QreLambda//---------------static Portion *GSM_QreLambda_Behav(GSM &, Portion** param){  BehavSolution *bs = ((BehavPortion*) param[0])->Value();  if (bs->Creator() != "Qre[EFG]" && bs->Creator() != "Qre[NFG]") {    return new NullPortion(porNUMBER);  }  return new NumberPortion(bs->QreLambda());}static Portion *GSM_QreLambda_Mixed(GSM &, Portion** param){  MixedSolution *bs = ((MixedPortion*) param[0])->Value();  if (bs->Creator() != "Qre[NFG]" && bs->Creator() != "QreGrid[NFG]") {    return new NullPortion(porNUMBER);  }  return new NumberPortion(bs->QreLambda());}//----------------// InfosetProb//----------------static Portion *GSM_InfosetProb(GSM &, Portion **param){  if( param[1]->Spec().Type == porNULL )    return new NullPortion( porNUMBER );  BehavSolution *bp = ((BehavPortion *) param[0])->Value();  Infoset* s = ((InfosetPortion*) param[1])->Value();  //  if (s->IsChanceInfoset())  //    throw gclRuntimeError("Not implemented for chance infosets");  return new NumberPortion(bp->IsetProb(s));}//---------// PolishEq//---------static Portion *GSM_PolishEq_Behav(GSM &, Portion **param){  BehavSolution *P = new     BehavSolution((*((BehavPortion *) param[0])->Value()).PolishEq());  BehavPortion *result = new BehavPortion(P);  return result;}static Portion *GSM_PolishEq_Mixed(GSM &, Portion **param){  MixedSolution *P = new     MixedSolution((*((MixedPortion *) param[0])->Value()).PolishEq());  MixedPortion *result = new MixedPortion(P);  return result;}//----------------// InfosetValue//----------------static Portion *GSM_InfosetValue(GSM &, Portion **param){  if( param[1]->Spec().Type == porNULL )    return new NullPortion( porNUMBER );  BehavSolution *bp = ((BehavPortion *) param[0])->Value();  Infoset* s = ((InfosetPortion*) param[1])->Value();  if (s->IsChanceInfoset())    return new NullPortion( porNUMBER );  return new NumberPortion(bp->IsetValue(s));}//---------// IsNash//---------static Portion *GSM_IsNash_Behav(GSM &, Portion **param){  BehavSolution *P = ((BehavPortion *) param[0])->Value();  return new BoolPortion(P->IsNash());}static Portion *GSM_IsANFNash_Behav(GSM &, Portion **param){  BehavSolution *P = ((BehavPortion *) param[0])->Value();  return new BoolPortion(P->IsANFNash());}static Portion *GSM_IsNash_Mixed(GSM &, Portion **param){  MixedSolution *P = ((MixedPortion*) param[0])->Value();  return new BoolPortion(P->IsNash());}//-------------// IsPerfect//-------------static Portion *GSM_IsPerfect(GSM &, Portion **param){  MixedSolution *P = ((MixedPortion*) param[0])->Value();  return new BoolPortion(P->IsPerfect());}//---------------// IsSequential//---------------static Portion *GSM_IsSequential(GSM &, Portion **param){  BehavSolution *P = ((BehavPortion *) param[0])->Value();  return new BoolPortion(P->IsSequential());}//--------------------// IsSubgamePerfect//--------------------static Portion *GSM_IsSubgamePerfect(GSM &, Portion **param){  BehavSolution *P = ((BehavPortion *) param[0])->Value();  return new BoolPortion(P->IsSubgamePerfect());}//-------------// LiapValue//-------------static Portion *GSM_LiapValue_Behav(GSM &, Portion **param){  BehavSolution *P = ((BehavPortion *) param[0])->Value();  return new NumberPortion(P->LiapValue());}static Portion *GSM_LiapValue_Mixed(GSM &, Portion **param){  MixedSolution *P = ((MixedPortion*) param[0])->Value();  return new NumberPortion(P->LiapValue());}//-------------// Accuracy//-------------static Portion *GSM_Accuracy_Behav(GSM &, Portion **param){  BehavSolution *P = ((BehavPortion *) param[0])->Value();  return new NumberPortion(P->Epsilon());}static Portion *GSM_Accuracy_Mixed(GSM &, Portion **param){  MixedSolution *P = ((MixedPortion*) param[0])->Value();  return new NumberPortion(P->Epsilon());}//----------// Mixed//----------Portion* GSM_Mixed(GSM &, Portion** param){  NFSupport *S = ((NfSupportPortion *) param[0])->Value();  return new MixedPortion(new MixedSolution(MixedProfile<gNumber>(*S)));}//----------------// NodeValue//----------------static Portion *GSM_NodeValue(GSM &, Portion **param){  BehavSolution *bp = ((BehavPortion *) param[0])->Value();  EFPlayer *p = ((EfPlayerPortion *) param[1])->Value();  Node* n = ((NodePortion*) param[2])->Value();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?