solfunc.cc

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

CC
688
字号
  return new NumberPortion(bp->NodeValue(n)[p->GetNumber()]);}//----------------// RealizProb//----------------static Portion *GSM_RealizProb(GSM &, Portion **param){  BehavSolution *bp = ((BehavPortion *) param[0])->Value();  Node* n = ((NodePortion*) param[1])->Value();    return new NumberPortion(bp->RealizProb(n)); }  //-----------// Regret//-----------static Portion *GSM_Regret_Mixed(GSM &, Portion **param){  MixedProfile<gNumber> P(*(*((MixedPortion*) param[0])->Value()).Profile());  Strategy* s = ((StrategyPortion*) param[1])->Value();  NFPlayer* p = s->Player();  Nfg &n = p->Game();  gPVector<gNumber> v(n.NumStrats());  P.Regret(v);  return new NumberPortion(v(p->GetNumber(), s->Number()));}static Portion *GSM_Regret_Behav(GSM &, Portion **param){  BehavSolution *P = ((BehavPortion *) param[0])->Value();  const Action* a = ((ActionPortion*) param[1])->Value();  if (a->BelongsTo()->IsChanceInfoset())    return new NullPortion(porNUMBER);    return new NumberPortion(P->Regret(a));}//------------// Regrets//------------static Portion *GSM_Regrets_Mixed(GSM &, Portion **param){  MixedProfile<gNumber> profile(*(*((MixedPortion *) param[0])->Value()).Profile());  gPVector<gNumber> v(profile.Game().NumStrats());  profile.Regret(v);  ListPortion *por = new ListPortion;    for (int pl = 1; pl <= profile.Lengths().Length(); pl++)  {    ListPortion *p1 = new ListPortion;    for (int st = 1; st <= profile.Lengths()[pl]; st++)      p1->Append(new NumberPortion(v(pl, st)));    por->Append(p1);  }  return por;}static Portion *GSM_NfgRegrets_Behav(GSM &, Portion **param){  BehavSolution *bp = ((BehavPortion *) param[0])->Value();  gPVector<gNumber> v((*bp).ReducedNormalFormRegret());  ListPortion *por = new ListPortion;  for (int pl = 1; pl <= v.Lengths().Length(); pl++)  {    ListPortion *p1 = new ListPortion;    for (int st = 1; st <= v.Lengths()[pl]; st++)      p1->Append(new NumberPortion(v(pl, st)));    por->Append(p1);  }  return por;}//-------------------// SetActionProb//-------------------static Portion *GSM_SetActionProb(GSM &, Portion **param){  BehavSolution *P = new BehavSolution(*((BehavPortion *) param[0])->Value());  Action *action = ((ActionPortion *) param[1])->Value();  gNumber value = ((NumberPortion *) param[2])->Value();    //  P->Set(action, value);  (*P)[action] = value;  ((BehavPortion *) param[0])->SetValue(P);  return param[0]->RefCopy();}//-----------------// SetActionProbs//-----------------static Portion *GSM_SetActionProbs(GSM &, Portion **param){  int i;  int j;  int k;  Portion* p3;  int PlayerNum = 0;  int InfosetNum = 0;    BehavSolution *P = new BehavSolution(*((BehavPortion*) param[0])->Value());  efgGame &E = P->GetGame();  gArray< EFPlayer* > player = E.Players();    for(i = 1; i <= E.NumPlayers(); i++)  {    for(j = 1; j <= E.Players()[i]->NumInfosets(); j++)    {      if(((InfosetPortion*) param[1])->Value() ==	 E.Players()[i]->Infosets()[j])      {	PlayerNum = i;	InfosetNum = j;	break;      }    }  }    if (((ListPortion*) param[2])->Length() !=       P->Support().NumActions(PlayerNum, InfosetNum))  {    delete P;    throw gclRuntimeError("Mismatching number of actions");  }    for(k = 1;       k <= E.Players()[PlayerNum]->Infosets()[InfosetNum]->NumActions();      k++)  {    p3 = ((ListPortion*) param[2])->SubscriptCopy(k);    if(p3->Spec().ListDepth > 0)    {      delete p3;      delete P;      throw gclRuntimeError("Mismatching dimensionality");    }    assert(p3->Spec().Type == porNUMBER);    P->Set((E.Players()[PlayerNum]->Infosets()[InfosetNum]->Actions()[k]),	   ((NumberPortion*) p3)->Value());    delete p3;  }  ((BehavPortion *) param[0])->SetValue(P);  return param[0]->RefCopy();}//-------------------// SetStrategyProb//-------------------static Portion *GSM_SetStrategyProb(GSM &, Portion **param){  MixedSolution *P = new MixedSolution(*((MixedPortion *) param[0])->Value());  Strategy *strategy = ((StrategyPortion *) param[1])->Value();  gNumber value = ((NumberPortion *) param[2])->Value();  P->Set(strategy, value);  ((MixedPortion *) param[0])->SetValue(P);  return param[0]->RefCopy();}//-------------------// SetStrategyProbs//-------------------static Portion *GSM_SetStrategyProbs(GSM &, Portion **param){  NFPlayer *player = ((NfPlayerPortion *) param[1])->Value();  MixedSolution *P = new MixedSolution(*((MixedPortion *) param[0])->Value());    if (((ListPortion*) param[2])->Length() != player->NumStrats()) {    delete P;    throw gclRuntimeError("Mismatching number of strategies");  }  for (int st = 1; st <= player->NumStrats(); st++) {    Portion *p2 = ((ListPortion*) param[2])->SubscriptCopy(st);    if (p2->Spec().ListDepth > 0) {      delete p2;      delete P;      throw gclRuntimeError("Mismatching dimensionality");    }    P->Set(player->Strategies()[st], ((NumberPortion*) p2)->Value());    delete p2;  }  ((MixedPortion *) param[0])->SetValue(P);  return param[0]->RefCopy();}//----------------// StrategyProb//----------------static Portion *GSM_StrategyProb(GSM &, Portion **param){  const MixedSolution *profile = ((MixedPortion *) param[0])->Value();  Strategy* strategy = ((StrategyPortion*) param[1])->Value();  return new NumberPortion((*profile)(strategy));}//----------------// StrategyProbs//----------------static Portion *GSM_StrategyProbs(GSM &, Portion **param){  const MixedSolution *profile = ((MixedPortion *) param[0])->Value();  const Nfg &nfg = profile->Game();  ListPortion *por = new ListPortion;  for (int pl = 1; pl <= nfg.NumPlayers(); pl++)  {    NFPlayer *player = nfg.Players()[pl];    ListPortion *p1 = new ListPortion;    for (int st = 1; st <= player->NumStrats(); st++) {      Strategy *strategy = player->Strategies()[st];      p1->Append(new NumberPortion((*profile)(strategy)));    }    por->Append(p1);  }  return por;}//------------------// StrategyValue//------------------static Portion *GSM_StrategyValue(GSM &, Portion **param){  MixedSolution *profile = ((MixedPortion *) param[0])->Value();  Strategy *strategy = ((StrategyPortion*) param[1])->Value();  return new NumberPortion(profile->Payoff(strategy->Player(), strategy));}//---------------// Support//---------------static Portion *GSM_Support_Behav(GSM &, Portion** param){  BehavSolution *P = ((BehavPortion *) param[0])->Value();  return new EfSupportPortion(new EFSupport(P->Support()));}static Portion *GSM_Support_Mixed(GSM &, Portion** param){  MixedSolution *P = ((MixedPortion *) param[0])->Value();  return new NfSupportPortion(new NFSupport(P->Support()));}void Init_solfunc(GSM *gsm){  static struct { char *sig; Portion *(*func)(GSM &, Portion **); } ftable[] =    { { "Accuracy[profile->BEHAV] =: NUMBER", GSM_Accuracy_Behav },      { "Accuracy[profile->MIXED] =: NUMBER", GSM_Accuracy_Mixed },      { "ActionProb[profile->BEHAV, action->ACTION] =: NUMBER", 	GSM_ActionProb },      { "ActionValue[profile->BEHAV, action->ACTION] =: NUMBER",	GSM_ActionValue },      { "Behav[support->EFSUPPORT] =: BEHAV", GSM_Behav },      { "Belief[profile->BEHAV, node->NODE] =: NUMBER", GSM_Belief },      { "Game[profile->MIXED] =: NFG", GSM_Game_Mixed },      { "Game[profile->BEHAV] =: EFG", GSM_Game_EfgTypes },      { "Game[support->NFSUPPORT] =: NFG", GSM_Game_NfSupport },      { "Game[support->EFSUPPORT] =: EFG", GSM_Game_EfgTypes },      { "Game[basis->EFBASIS] =: EFG", GSM_Game_EfgTypes },      { "Creator[profile->MIXED] =: TEXT", GSM_Creator_Mixed },      { "Creator[profile->BEHAV] =: TEXT", GSM_Creator_Behav },      { "QreLambda[profile->MIXED] =: NUMBER", GSM_QreLambda_Mixed },      { "QreLambda[profile->BEHAV] =: NUMBER", GSM_QreLambda_Behav },      { "InfosetProb[profile->BEHAV, infoset->INFOSET*] =: NUMBER",	GSM_InfosetProb },      { "InfosetValue[profile->BEHAV, infoset->INFOSET*] =: NUMBER",	GSM_InfosetValue },      { "IsNash[profile->BEHAV] =: BOOLEAN", GSM_IsNash_Behav },      { "PolishEq[profile->BEHAV] =: BEHAV", GSM_PolishEq_Behav },      { "IsANFNash[profile->BEHAV] =: BOOLEAN", GSM_IsANFNash_Behav },      { "IsNash[profile->MIXED] =: BOOLEAN", GSM_IsNash_Mixed },      { "PolishEq[profile->MIXED] =: MIXED", GSM_PolishEq_Mixed },      { "IsPerfect[profile->MIXED] =: BOOLEAN", GSM_IsPerfect },      { "IsSequential[profile->BEHAV] =: BOOLEAN", GSM_IsSequential },      { "IsSubgamePerfect[profile->BEHAV] =: BOOLEAN", GSM_IsSubgamePerfect },      { "LiapValue[profile->BEHAV] =: NUMBER", GSM_LiapValue_Behav },      { "LiapValue[profile->MIXED] =: NUMBER", GSM_LiapValue_Mixed },      { "Mixed[support->NFSUPPORT] =: MIXED", GSM_Mixed },      { "NodeValue[profile->BEHAV, player->EFPLAYER, node->NODE] =: NUMBER",	GSM_NodeValue },      { "RealizProb[profile->BEHAV, node->NODE] =: NUMBER", GSM_RealizProb },      { "Regret[profile->BEHAV, action->ACTION] =: NUMBER",	GSM_Regret_Behav },      { "Regret[profile->MIXED, strategy->STRATEGY] =: NUMBER",	GSM_Regret_Mixed },      { "NfgRegrets[profile->BEHAV] =: LIST(NUMBER)", 	GSM_NfgRegrets_Behav },      { "Regrets[profile->MIXED] =: LIST(LIST(NUMBER))", GSM_Regrets_Mixed },      { "SetActionProb[profile<->BEHAV, action->ACTION, value->NUMBER =: BEHAV", GSM_SetActionProb },      { "SetActionProbs[profile<->BEHAV, infoset->INFOSET, value->LIST(NUMBER) =: BEHAV", GSM_SetActionProbs },      { "SetStrategyProb[profile<->MIXED, strategy->STRATEGY, value->NUMBER =: MIXED", GSM_SetStrategyProb },      { "SetStrategyProbs[profile<->MIXED, player->NFPLAYER, value->LIST(NUMBER) =: MIXED", GSM_SetStrategyProbs },      { "StrategyProb[profile->MIXED, strategy->STRATEGY] =: NUMBER",	GSM_StrategyProb },      { "StrategyProbs[profile->MIXED] =: LIST(LIST(NUMBER))",	GSM_StrategyProbs },      { "StrategyValue[profile->MIXED, strategy->STRATEGY] =: NUMBER",	GSM_StrategyValue },      { "Support[profile->BEHAV] =: EFSUPPORT", GSM_Support_Behav },      { "Support[profile->MIXED] =: NFSUPPORT", GSM_Support_Mixed },      { 0, 0 }    };  for (int i = 0; ftable[i].sig != 0; i++) {    gsm->AddFunction(new gclFunction(*gsm, ftable[i].sig, ftable[i].func,				     funcLISTABLE | funcGAMEMATCH));  }}

⌨️ 快捷键说明

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