diff --git a/src/core/array.h b/src/core/array.h index 223666947..1094a93b8 100644 --- a/src/core/array.h +++ b/src/core/array.h @@ -62,12 +62,14 @@ template class Array { public: class iterator { + friend class Array; + private: Array *m_array; int m_index; public: - using iterator_category = std::forward_iterator_tag; + using iterator_category = std::bidirectional_iterator_tag; using difference_type = std::ptrdiff_t; using value_type = T; using pointer = value_type *; @@ -81,6 +83,11 @@ template class Array { m_index++; return *this; } + iterator &operator--() + { + m_index--; + return *this; + } iterator operator++(int) { auto ret = *this; @@ -100,7 +107,7 @@ template class Array { int m_index; public: - using iterator_category = std::forward_iterator_tag; + using iterator_category = std::bidirectional_iterator_tag; using difference_type = std::ptrdiff_t; using value_type = T; using pointer = value_type *; @@ -114,6 +121,11 @@ template class Array { m_index++; return *this; } + const_iterator &operator--() + { + m_index--; + return *this; + } const_iterator operator++(int) { auto ret = *this; @@ -257,9 +269,6 @@ template class Array { ; return (i <= this->maxdex) ? i : (mindex - 1); } - - /// Return true if the element is currently residing in the array - bool Contains(const T &t) const { return Find(t) != mindex - 1; } //@} /// @name Modifying the contents of the array @@ -276,6 +285,8 @@ template class Array { : ((n > this->maxdex + 1) ? this->maxdex + 1 : n)); } + void erase(iterator pos) { Remove(pos.m_index); } + /// \brief Remove an element from the array. /// /// Remove the element at a given index from the array. Returns the value @@ -333,9 +344,11 @@ template class Array { /// leaving the container with a size of 0. void clear() { - delete[] (this->data + this->mindex); - this->data = 0; - this->maxdex = this->mindex - 1; + if (maxdex >= mindex) { + delete[] (data + mindex); + } + data = nullptr; + maxdex = mindex - 1; } ///@} }; diff --git a/src/games/game.cc b/src/games/game.cc index 000d316f5..bb4588654 100644 --- a/src/games/game.cc +++ b/src/games/game.cc @@ -60,7 +60,8 @@ void GameStrategyRep::DeleteStrategy() } m_player->GetGame()->IncrementVersion(); - m_player->m_strategies.Remove(m_player->m_strategies.Find(this)); + m_player->m_strategies.erase( + std::find(m_player->m_strategies.begin(), m_player->m_strategies.end(), this)); for (int st = 1; st <= m_player->m_strategies.Length(); st++) { m_player->m_strategies[st]->m_number = st; } diff --git a/src/games/game.h b/src/games/game.h index a6eb14294..3f4708ab2 100644 --- a/src/games/game.h +++ b/src/games/game.h @@ -351,7 +351,6 @@ class GameNodeRep : public GameObject { virtual void SetLabel(const std::string &p_label) = 0; virtual int GetNumber() const = 0; - virtual int NumberInInfoset() const = 0; virtual int NumChildren() const = 0; virtual GameNode GetChild(int i) const = 0; diff --git a/src/games/gameexpl.cc b/src/games/gameexpl.cc index a7083e7f1..5aa7313bc 100644 --- a/src/games/gameexpl.cc +++ b/src/games/gameexpl.cc @@ -108,7 +108,7 @@ Array GameExplicitRep::NumStrategies() const { const_cast(this)->BuildComputedValues(); Array dim(m_players.size()); - for (int pl = 1; pl <= m_players.size(); pl++) { + for (size_t pl = 1; pl <= m_players.size(); pl++) { dim[pl] = m_players[pl]->m_strategies.size(); } return dim; diff --git a/src/games/gametable.cc b/src/games/gametable.cc index 4c0e12520..8a3e4cd8d 100644 --- a/src/games/gametable.cc +++ b/src/games/gametable.cc @@ -409,7 +409,8 @@ void GameTableRep::DeleteOutcome(const GameOutcome &p_outcome) m_results[i] = 0; } } - m_outcomes.Remove(m_outcomes.Find(p_outcome))->Invalidate(); + p_outcome->Invalidate(); + m_outcomes.erase(std::find(m_outcomes.begin(), m_outcomes.end(), p_outcome)); for (int outc = 1; outc <= m_outcomes.Length(); outc++) { m_outcomes[outc]->m_number = outc; } diff --git a/src/games/gametree.cc b/src/games/gametree.cc index e1e564f22..1bb9e7ecc 100644 --- a/src/games/gametree.cc +++ b/src/games/gametree.cc @@ -200,7 +200,8 @@ void GameTreeInfosetRep::SetPlayer(GamePlayer p_player) } m_efg->IncrementVersion(); - m_player->m_infosets.Remove(m_player->m_infosets.Find(this)); + m_player->m_infosets.erase( + std::find(m_player->m_infosets.begin(), m_player->m_infosets.end(), this)); m_player = p_player; p_player->m_infosets.push_back(this); @@ -269,13 +270,15 @@ void GameTreeInfosetRep::RemoveAction(int which) void GameTreeInfosetRep::RemoveMember(GameTreeNodeRep *p_node) { m_efg->IncrementVersion(); - m_members.Remove(m_members.Find(p_node)); - if (m_members.Length() == 0) { - m_player->m_infosets.Remove(m_player->m_infosets.Find(this)); - for (int i = 1; i <= m_player->m_infosets.Length(); i++) { - m_player->m_infosets[i]->m_number = i; - } + m_members.erase(std::find(m_members.begin(), m_members.end(), p_node)); + if (m_members.empty()) { + m_player->m_infosets.erase( + std::find(m_player->m_infosets.begin(), m_player->m_infosets.end(), this)); Invalidate(); + int iset = 1; + for (auto &infoset : m_player->m_infosets) { + infoset->m_number = iset++; + } } } @@ -348,28 +351,18 @@ Array GameTreeNodeRep::GetChildren() const GameNode GameTreeNodeRep::GetNextSibling() const { - if (!m_parent) { + if (!m_parent || m_parent->children.back() == this) { return nullptr; } - if (m_parent->children.back() == this) { - return nullptr; - } - else { - return m_parent->children[m_parent->children.Find(const_cast(this)) + 1]; - } + return *std::next(std::find(m_parent->children.begin(), m_parent->children.end(), this)); } GameNode GameTreeNodeRep::GetPriorSibling() const { - if (!m_parent) { + if (!m_parent || m_parent->children.front() == this) { return nullptr; } - if (m_parent->children.front() == this) { - return nullptr; - } - else { - return m_parent->children[m_parent->children.Find(const_cast(this)) - 1]; - } + return *std::prev(std::find(m_parent->children.begin(), m_parent->children.end(), this)); } GameAction GameTreeNodeRep::GetPriorAction() const @@ -451,11 +444,12 @@ void GameTreeNodeRep::DeleteParent() m_efg->IncrementVersion(); GameTreeNodeRep *oldParent = m_parent; - oldParent->children.Remove(oldParent->children.Find(this)); + oldParent->children.erase( + std::find(oldParent->children.begin(), oldParent->children.end(), this)); oldParent->DeleteTree(); m_parent = oldParent->m_parent; if (m_parent) { - m_parent->children[m_parent->children.Find(oldParent)] = this; + std::replace(m_parent->children.begin(), m_parent->children.end(), oldParent, this); } else { m_efg->m_root = this; @@ -538,21 +532,9 @@ void GameTreeNodeRep::MoveTree(GameNode p_src) } m_efg->IncrementVersion(); auto *src = dynamic_cast(p_src.operator->()); - - if (src->m_parent == m_parent) { - int srcChild = src->m_parent->children.Find(src); - int destChild = src->m_parent->children.Find(this); - src->m_parent->children[srcChild] = this; - src->m_parent->children[destChild] = src; - } - else { - GameTreeNodeRep *parent = src->m_parent; - parent->children[parent->children.Find(src)] = this; - m_parent->children[m_parent->children.Find(this)] = src; - src->m_parent = m_parent; - m_parent = parent; - } - + std::iter_swap(std::find(src->m_parent->children.begin(), src->m_parent->children.end(), src), + std::find(m_parent->children.begin(), m_parent->children.end(), this)); + std::swap(src->m_parent, m_parent); m_label = ""; outcome = nullptr; @@ -675,7 +657,7 @@ GameInfoset GameTreeNodeRep::InsertMove(GameInfoset p_infoset) dynamic_cast(p_infoset.operator->())->AddMember(newNode); if (m_parent) { - m_parent->children[m_parent->children.Find(this)] = newNode; + std::replace(m_parent->children.begin(), m_parent->children.end(), this, newNode); } else { m_efg->m_root = newNode; @@ -886,12 +868,12 @@ void GameTreeRep::Canonicalize() void GameTreeRep::ClearComputedValues() const { - for (int pl = 1; pl <= m_players.Length(); pl++) { - while (m_players[pl]->m_strategies.Length() > 0) { - m_players[pl]->m_strategies.Remove(1)->Invalidate(); + for (auto player : m_players) { + for (auto strategy : player->m_strategies) { + strategy->Invalidate(); } + player->m_strategies.clear(); } - m_computedValues = false; } @@ -900,13 +882,10 @@ void GameTreeRep::BuildComputedValues() if (m_computedValues) { return; } - Canonicalize(); - - for (int pl = 1; pl <= m_players.Length(); pl++) { - m_players[pl]->MakeReducedStrats(m_root, nullptr); + for (const auto &player : m_players) { + player->MakeReducedStrats(m_root, nullptr); } - m_computedValues = true; } @@ -1073,9 +1052,11 @@ void GameTreeRep::DeleteOutcome(const GameOutcome &p_outcome) { IncrementVersion(); m_root->DeleteOutcome(p_outcome); - m_outcomes.Remove(m_outcomes.Find(p_outcome))->Invalidate(); - for (int outc = 1; outc <= m_outcomes.Length(); outc++) { - m_outcomes[outc]->m_number = outc; + m_outcomes.erase(std::find(m_outcomes.begin(), m_outcomes.end(), p_outcome)); + p_outcome->Invalidate(); + int outc = 1; + for (auto &outcome : m_outcomes) { + outcome->m_number = outc++; } ClearComputedValues(); } @@ -1110,7 +1091,7 @@ Game GameTreeRep::SetChanceProbs(const GameInfoset &p_infoset, const ArrayNumActions() != p_probs.size()) { + if (p_infoset->NumActions() != static_cast(p_probs.size())) { throw DimensionException("The number of probabilities given must match the number of actions"); } IncrementVersion(); diff --git a/src/games/gametree.h b/src/games/gametree.h index 46a1df6d3..12b1b3eae 100644 --- a/src/games/gametree.h +++ b/src/games/gametree.h @@ -156,11 +156,6 @@ class GameTreeNodeRep : public GameNodeRep { void SetLabel(const std::string &p_label) override { m_label = p_label; } int GetNumber() const override { return number; } - int NumberInInfoset() const override - { - return infoset->m_members.Find(const_cast(this)); - } - int NumChildren() const override { return children.size(); } GameNode GetChild(int i) const override { return children[i]; } GameNode GetChild(const GameAction &p_action) const override diff --git a/src/games/stratpure.cc b/src/games/stratpure.cc index 13a6b7a85..7eb84bf3b 100644 --- a/src/games/stratpure.cc +++ b/src/games/stratpure.cc @@ -32,7 +32,7 @@ namespace Gambit { PureStrategyProfileRep::PureStrategyProfileRep(const Game &p_game) : m_nfg(p_game), m_profile(p_game->NumPlayers()) { - for (size_t pl = 1; pl <= m_nfg->NumPlayers(); pl++) { + for (int pl = 1; pl <= m_nfg->NumPlayers(); pl++) { m_profile[pl] = m_nfg->GetPlayer(pl)->GetStrategy(1); } } diff --git a/src/gui/analysis.cc b/src/gui/analysis.cc index 354133b5b..0924582db 100644 --- a/src/gui/analysis.cc +++ b/src/gui/analysis.cc @@ -59,7 +59,7 @@ MixedStrategyProfile OutputToMixedProfile(gbtGameDocument *p_doc, const wxStr if (tok.GetNextToken() == wxT("NE")) { if (tok.CountTokens() == (unsigned int)profile.MixedProfileLength()) { - for (int i = 1; i <= profile.MixedProfileLength(); i++) { + for (size_t i = 1; i <= profile.MixedProfileLength(); i++) { profile[i] = lexical_cast(std::string((const char *)tok.GetNextToken().mb_str())); } @@ -79,7 +79,7 @@ MixedBehaviorProfile OutputToBehavProfile(gbtGameDocument *p_doc, const wxStr if (tok.GetNextToken() == wxT("NE")) { if (tok.CountTokens() == (unsigned int)profile.BehaviorProfileLength()) { - for (int i = 1; i <= profile.BehaviorProfileLength(); i++) { + for (size_t i = 1; i <= profile.BehaviorProfileLength(); i++) { profile[i] = lexical_cast(std::string((const char *)tok.GetNextToken().mb_str())); } @@ -156,7 +156,7 @@ MixedStrategyProfile TextToMixedProfile(gbtGameDocument *p_doc, const wxStrin wxStringTokenizer tok(p_text, wxT(",")); - for (int i = 1; i <= profile.MixedProfileLength(); i++) { + for (size_t i = 1; i <= profile.MixedProfileLength(); i++) { profile[i] = lexical_cast(std::string((const char *)tok.GetNextToken().mb_str())); } @@ -169,7 +169,7 @@ MixedBehaviorProfile TextToBehavProfile(gbtGameDocument *p_doc, const wxStrin MixedBehaviorProfile profile(p_doc->GetGame()); wxStringTokenizer tok(p_text, wxT(",")); - for (int i = 1; i <= profile.BehaviorProfileLength(); i++) { + for (size_t i = 1; i <= profile.BehaviorProfileLength(); i++) { profile[i] = lexical_cast(std::string((const char *)tok.GetNextToken().mb_str())); } @@ -441,7 +441,7 @@ template void gbtAnalysisProfileList::Save(std::ostream &p_file) co for (int j = 1; j <= NumProfiles(); j++) { const MixedBehaviorProfile &behav = *m_behavProfiles[j]; p_file << "\n"; - for (int k = 1; k <= behav.BehaviorProfileLength(); k++) { + for (size_t k = 1; k <= behav.BehaviorProfileLength(); k++) { p_file << behav[k]; if (k < behav.BehaviorProfileLength()) { p_file << ","; @@ -457,7 +457,7 @@ template void gbtAnalysisProfileList::Save(std::ostream &p_file) co for (int j = 1; j <= NumProfiles(); j++) { const MixedStrategyProfile &mixed = *m_mixedProfiles[j]; p_file << "\n"; - for (int k = 1; k <= mixed.MixedProfileLength(); k++) { + for (size_t k = 1; k <= mixed.MixedProfileLength(); k++) { p_file << mixed[k]; if (k < mixed.MixedProfileLength()) { p_file << ","; diff --git a/src/gui/app.h b/src/gui/app.h index 98bda15a8..e44725884 100644 --- a/src/gui/app.h +++ b/src/gui/app.h @@ -68,7 +68,10 @@ class gbtApplication : public wxApp { //! //@{ void AddDocument(gbtGameDocument *p_doc) { m_documents.push_back(p_doc); } - void RemoveDocument(gbtGameDocument *p_doc) { m_documents.Remove(m_documents.Find(p_doc)); } + void RemoveDocument(gbtGameDocument *p_doc) + { + m_documents.erase(std::find(m_documents.begin(), m_documents.end(), p_doc)); + } bool AreDocumentsModified() const; //@} }; diff --git a/src/gui/dlefglogit.cc b/src/gui/dlefglogit.cc index e04a5dc57..4d763d5fc 100644 --- a/src/gui/dlefglogit.cc +++ b/src/gui/dlefglogit.cc @@ -178,7 +178,7 @@ void gbtLogitBehavList::AddProfile(const wxString &p_text, bool p_forceShow) m_lambdas.push_back((double)Gambit::lexical_cast( std::string((const char *)tok.GetNextToken().mb_str()))); - for (int i = 1; i <= profile->BehaviorProfileLength(); i++) { + for (size_t i = 1; i <= profile->BehaviorProfileLength(); i++) { (*profile)[i] = Gambit::lexical_cast( std::string((const char *)tok.GetNextToken().mb_str())); } @@ -207,8 +207,8 @@ END_EVENT_TABLE() gbtLogitBehavDialog::gbtLogitBehavDialog(wxWindow *p_parent, gbtGameDocument *p_doc) : wxDialog(p_parent, wxID_ANY, wxT("Compute quantal response equilibria"), wxDefaultPosition), - m_doc(p_doc), m_process(nullptr), m_timer(this, GBT_ID_TIMER), - m_behavList(new gbtLogitBehavList(this, m_doc)) + m_doc(p_doc), m_process(nullptr), m_behavList(new gbtLogitBehavList(this, m_doc)), + m_timer(this, GBT_ID_TIMER) { auto *sizer = new wxBoxSizer(wxVERTICAL); diff --git a/src/gui/dlnfglogit.cc b/src/gui/dlnfglogit.cc index 925d0b561..1da4fc182 100644 --- a/src/gui/dlnfglogit.cc +++ b/src/gui/dlnfglogit.cc @@ -77,7 +77,7 @@ void LogitMixedBranch::AddProfile(const wxString &p_text) m_lambdas.push_back( (double)lexical_cast(std::string((const char *)tok.GetNextToken().mb_str()))); - for (int i = 1; i <= profile->MixedProfileLength(); i++) { + for (size_t i = 1; i <= profile->MixedProfileLength(); i++) { (*profile)[i] = lexical_cast(std::string((const char *)tok.GetNextToken().mb_str())); } @@ -456,8 +456,8 @@ class LogitPlotPanel : public wxPanel { LogitPlotPanel::LogitPlotPanel(wxWindow *p_parent, gbtGameDocument *p_doc) : wxPanel(p_parent, wxID_ANY), m_doc(p_doc), m_branch(p_doc), - m_plotCtrl(new gbtLogitPlotCtrl(this, p_doc)), - m_plotStrategies(new gbtLogitPlotStrategyList(this, p_doc)) + m_plotStrategies(new gbtLogitPlotStrategyList(this, p_doc)), + m_plotCtrl(new gbtLogitPlotCtrl(this, p_doc)) { m_plotCtrl->SetSizeHints(wxSize(600, 400)); @@ -605,7 +605,7 @@ END_EVENT_TABLE() LogitMixedDialog::LogitMixedDialog(wxWindow *p_parent, gbtGameDocument *p_doc) : wxDialog(p_parent, wxID_ANY, wxT("Compute quantal response equilibria"), wxDefaultPosition), - m_doc(p_doc), m_timer(this, GBT_ID_TIMER), m_plot(new LogitPlotPanel(this, m_doc)) + m_doc(p_doc), m_plot(new LogitPlotPanel(this, m_doc)), m_timer(this, GBT_ID_TIMER) { auto *sizer = new wxBoxSizer(wxVERTICAL); diff --git a/src/gui/efglayout.cc b/src/gui/efglayout.cc index 3aa5d5d9c..861cb73bd 100644 --- a/src/gui/efglayout.cc +++ b/src/gui/efglayout.cc @@ -325,9 +325,9 @@ gbtTreeLayout::gbtTreeLayout(gbtEfgDisplay *p_parent, gbtGameDocument *p_doc) Gambit::GameNode gbtTreeLayout::NodeHitTest(int p_x, int p_y) const { - for (int i = 1; i <= m_nodeList.Length(); i++) { - if (m_nodeList[i]->NodeHitTest(p_x, p_y)) { - return m_nodeList[i]->GetNode(); + for (const auto &entry : m_nodeList) { + if (entry->NodeHitTest(p_x, p_y)) { + return entry->GetNode(); } } return nullptr; @@ -335,9 +335,9 @@ Gambit::GameNode gbtTreeLayout::NodeHitTest(int p_x, int p_y) const Gambit::GameNode gbtTreeLayout::OutcomeHitTest(int p_x, int p_y) const { - for (int i = 1; i <= m_nodeList.Length(); i++) { - if (m_nodeList[i]->OutcomeHitTest(p_x, p_y)) { - return m_nodeList[i]->GetNode(); + for (const auto &entry : m_nodeList) { + if (entry->OutcomeHitTest(p_x, p_y)) { + return entry->GetNode(); } } return nullptr; @@ -345,9 +345,9 @@ Gambit::GameNode gbtTreeLayout::OutcomeHitTest(int p_x, int p_y) const Gambit::GameNode gbtTreeLayout::BranchAboveHitTest(int p_x, int p_y) const { - for (int i = 1; i <= m_nodeList.Length(); i++) { - if (m_nodeList[i]->BranchAboveHitTest(p_x, p_y)) { - return m_nodeList[i]->GetNode()->GetParent(); + for (const auto &entry : m_nodeList) { + if (entry->BranchAboveHitTest(p_x, p_y)) { + return entry->GetNode()->GetParent(); } } return nullptr; @@ -355,9 +355,9 @@ Gambit::GameNode gbtTreeLayout::BranchAboveHitTest(int p_x, int p_y) const Gambit::GameNode gbtTreeLayout::BranchBelowHitTest(int p_x, int p_y) const { - for (int i = 1; i <= m_nodeList.Length(); i++) { - if (m_nodeList[i]->BranchAboveHitTest(p_x, p_y)) { - return m_nodeList[i]->GetNode()->GetParent(); + for (const auto &entry : m_nodeList) { + if (entry->BranchAboveHitTest(p_x, p_y)) { + return entry->GetNode()->GetParent(); } } return nullptr; @@ -365,8 +365,7 @@ Gambit::GameNode gbtTreeLayout::BranchBelowHitTest(int p_x, int p_y) const Gambit::GameNode gbtTreeLayout::InfosetHitTest(int p_x, int p_y) const { - for (int i = 1; i <= m_nodeList.Length(); i++) { - gbtNodeEntry *entry = m_nodeList[i]; + for (const auto &entry : m_nodeList) { if (entry->GetNextMember() && entry->GetNode()->GetInfoset()) { if (p_x > entry->X() + entry->GetSublevel() * m_infosetSpacing - 2 && p_x < entry->X() + entry->GetSublevel() * m_infosetSpacing + 2) { @@ -514,9 +513,9 @@ gbtNodeEntry *gbtTreeLayout::GetValidChild(const Gambit::GameNode &e) gbtNodeEntry *gbtTreeLayout::GetEntry(const Gambit::GameNode &p_node) const { - for (int i = 1; i <= m_nodeList.Length(); i++) { - if (m_nodeList[i]->GetNode() == p_node) { - return m_nodeList[i]; + for (const auto &entry : m_nodeList) { + if (entry->GetNode() == p_node) { + return entry; } } return nullptr; @@ -526,9 +525,10 @@ Gambit::GameNode gbtTreeLayout::PriorSameLevel(const Gambit::GameNode &p_node) c { gbtNodeEntry *entry = GetEntry(p_node); if (entry) { - for (int i = m_nodeList.Find(entry) - 1; i >= 1; i--) { - if (m_nodeList[i]->GetLevel() == entry->GetLevel()) { - return m_nodeList[i]->GetNode(); + auto e = std::next(std::find(m_nodeList.rbegin(), m_nodeList.rend(), entry)); + while (e != m_nodeList.rend()) { + if ((*e)->GetLevel() == entry->GetLevel()) { + return (*e)->GetNode(); } } } @@ -539,10 +539,12 @@ Gambit::GameNode gbtTreeLayout::NextSameLevel(const Gambit::GameNode &p_node) co { gbtNodeEntry *entry = GetEntry(p_node); if (entry) { - for (int i = m_nodeList.Find(entry) + 1; i <= m_nodeList.Length(); i++) { - if (m_nodeList[i]->GetLevel() == entry->GetLevel()) { - return m_nodeList[i]->GetNode(); + auto e = std::next(std::find(m_nodeList.begin(), m_nodeList.end(), entry)); + while (e != m_nodeList.end()) { + if ((*e)->GetLevel() == entry->GetLevel()) { + return (*e)->GetNode(); } + ++e; } } return nullptr; @@ -578,7 +580,9 @@ int gbtTreeLayout::LayoutSubtree(const Gambit::GameNode &p_node, if (!p_node->GetPlayer()->IsChance() && !p_support.Contains(p_node->GetInfoset()->GetAction(i))) { - m_nodeList[p_node->GetChild(i)->GetNumber()]->SetInSupport(false); + (*std::find_if(m_nodeList.begin(), m_nodeList.end(), [&](const gbtNodeEntry *e) { + return e->GetNode() == p_node->GetChild(i); + }))->SetInSupport(false); } } entry->SetY((y1 + yn) / 2); @@ -632,8 +636,9 @@ gbtNodeEntry *gbtTreeLayout::NextInfoset(gbtNodeEntry *e) { const gbtStyle &draw_settings = m_doc->GetStyle(); - for (int pos = m_nodeList.Find(e) + 1; pos <= m_nodeList.Length(); pos++) { - gbtNodeEntry *e1 = m_nodeList[pos]; + auto entry = std::next(std::find(m_nodeList.begin(), m_nodeList.end(), e)); + while (entry != m_nodeList.end()) { + gbtNodeEntry *e1 = *entry; // infosets are the same and the nodes are on the same level if (e->GetNode()->GetInfoset() == e1->GetNode()->GetInfoset()) { if (draw_settings.InfosetConnect() == GBT_INFOSET_CONNECT_ALL) { @@ -643,6 +648,7 @@ gbtNodeEntry *gbtTreeLayout::NextInfoset(gbtNodeEntry *e) return e1; } } + ++entry; } return nullptr; } @@ -655,14 +661,12 @@ gbtNodeEntry *gbtTreeLayout::NextInfoset(gbtNodeEntry *e) // void gbtTreeLayout::CheckInfosetEntry(gbtNodeEntry *e) { - int pos; - gbtNodeEntry *infoset_entry, *e1; + gbtNodeEntry *infoset_entry; // Check if the infoset this entry belongs to (on this level) has already // been processed. If so, make this entry->num the same as the one already // processed and return infoset_entry = NextInfoset(e); - for (pos = 1; pos <= m_nodeList.Length(); pos++) { - e1 = m_nodeList[pos]; + for (const auto &e1 : m_nodeList) { // if the infosets are the same and they are on the same level and e1 has been processed if (e->GetNode()->GetInfoset() == e1->GetNode()->GetInfoset() && e->GetLevel() == e1->GetLevel() && e1->GetSublevel() > 0) { @@ -684,8 +688,7 @@ void gbtTreeLayout::CheckInfosetEntry(gbtNodeEntry *e) // find the entry on the same level with the maximum num. // This entry will have num = num+1. int num = 0; - for (pos = 1; pos <= m_nodeList.Length(); pos++) { - e1 = m_nodeList[pos]; + for (const auto &e1 : m_nodeList) { // Find the max num for this level if (e->GetLevel() == e1->GetLevel()) { num = std::max(e1->GetSublevel(), num); @@ -728,8 +731,7 @@ void gbtTreeLayout::UpdateTableInfosets() for (int i = 0; i <= m_maxLevel + 1; nums[i++] = 0) ; // find the max e->num for each level - for (int pos = 1; pos <= m_nodeList.Length(); pos++) { - gbtNodeEntry *entry = m_nodeList[pos]; + for (const auto &entry : m_nodeList) { nums[entry->GetLevel()] = std::max(entry->GetSublevel() + 1, nums[entry->GetLevel()]); } @@ -739,8 +741,7 @@ void gbtTreeLayout::UpdateTableInfosets() // now add the needed length to each level, and set maxX accordingly m_maxX = 0; - for (int pos = 1; pos <= m_nodeList.Length(); pos++) { - gbtNodeEntry *entry = m_nodeList[pos]; + for (const auto &entry : m_nodeList) { if (entry->GetLevel() != 0) { entry->SetX(entry->X() + (nums[entry->GetLevel() - 1] + entry->GetSublevel()) * m_infosetSpacing); @@ -751,8 +752,7 @@ void gbtTreeLayout::UpdateTableInfosets() void gbtTreeLayout::UpdateTableParents() { - for (int pos = 1; pos <= m_nodeList.Length(); pos++) { - gbtNodeEntry *e = m_nodeList[pos]; + for (const auto &e : m_nodeList) { e->SetParent((e->GetNode() == m_doc->GetGame()->GetRoot()) ? e : GetValidParent(e->GetNode())); } } @@ -762,7 +762,7 @@ void gbtTreeLayout::Layout(const Gambit::BehaviorSupportProfile &p_support) // Kinda kludgey; probably should query draw settings whenever needed. m_infosetSpacing = (m_doc->GetStyle().InfosetJoin() == GBT_INFOSET_JOIN_LINES) ? 10 : 40; - if (m_nodeList.Length() != m_doc->GetGame()->NumNodes()) { + if (m_nodeList.size() != m_doc->GetGame()->NumNodes()) { // A rebuild is in order; force it BuildNodeList(p_support); } @@ -815,10 +815,10 @@ void gbtTreeLayout::BuildNodeList(const Gambit::GameNode &p_node, void gbtTreeLayout::BuildNodeList(const Gambit::BehaviorSupportProfile &p_support) { - while (m_nodeList.Length() > 0) { - delete m_nodeList.Remove(1); + for (auto entry : m_nodeList) { + delete entry; } - + m_nodeList.clear(); m_maxLevel = 0; BuildNodeList(m_doc->GetGame()->GetRoot(), p_support, 0); } @@ -826,8 +826,7 @@ void gbtTreeLayout::BuildNodeList(const Gambit::BehaviorSupportProfile &p_suppor void gbtTreeLayout::GenerateLabels() { const gbtStyle &settings = m_doc->GetStyle(); - for (int i = 1; i <= m_nodeList.Length(); i++) { - gbtNodeEntry *entry = m_nodeList[i]; + for (const auto &entry : m_nodeList) { entry->SetNodeAboveLabel(CreateNodeLabel(entry, settings.NodeAboveLabel())); entry->SetNodeAboveFont(settings.GetFont()); entry->SetNodeBelowLabel(CreateNodeLabel(entry, settings.NodeBelowLabel())); @@ -877,8 +876,7 @@ void gbtTreeLayout::RenderSubtree(wxDC &p_dc, bool p_noHints) const { const gbtStyle &settings = m_doc->GetStyle(); - for (int pos = 1; pos <= m_nodeList.Length(); pos++) { - gbtNodeEntry *entry = m_nodeList[pos]; + for (const auto &entry : m_nodeList) { gbtNodeEntry *parentEntry = entry->GetParent(); if (entry->GetChildNumber() == 1) { diff --git a/src/gui/efglayout.h b/src/gui/efglayout.h index 5a419bd43..b0489686c 100644 --- a/src/gui/efglayout.h +++ b/src/gui/efglayout.h @@ -155,7 +155,7 @@ class gbtEfgDisplay; class gbtTreeLayout : public gbtGameView { private: /* gbtEfgDisplay *m_parent; */ - Gambit::Array m_nodeList; + std::list m_nodeList; mutable int m_maxX{0}, m_maxY{0}, m_maxLevel{0}; int m_infosetSpacing; diff --git a/src/gui/efgpanel.cc b/src/gui/efgpanel.cc index 3f0f86015..711b27c2f 100644 --- a/src/gui/efgpanel.cc +++ b/src/gui/efgpanel.cc @@ -622,8 +622,8 @@ END_EVENT_TABLE() gbtEfgPanel::gbtEfgPanel(wxWindow *p_parent, gbtGameDocument *p_doc) : wxPanel(p_parent, wxID_ANY), gbtGameView(p_doc), m_treeWindow(new gbtEfgDisplay(this, m_doc)), - m_playerToolbar(new gbtTreePlayerToolbar(this, m_doc)), - m_dominanceToolbar(new gbtBehavDominanceToolbar(this, m_doc)) + m_dominanceToolbar(new gbtBehavDominanceToolbar(this, m_doc)), + m_playerToolbar(new gbtTreePlayerToolbar(this, m_doc)) { auto *topSizer = new wxBoxSizer(wxVERTICAL); topSizer->Add(m_dominanceToolbar, 0, wxEXPAND, 0); diff --git a/src/gui/gamedoc.h b/src/gui/gamedoc.h index 0a1973b38..1f6ae07ed 100644 --- a/src/gui/gamedoc.h +++ b/src/gui/gamedoc.h @@ -216,8 +216,8 @@ class gbtGameDocument { void AddView(gbtGameView *p_view) { m_views.push_back(p_view); } void RemoveView(gbtGameView *p_view) { - m_views.Remove(m_views.Find(p_view)); - if (m_views.Length() == 0) { + m_views.erase(std::find(m_views.begin(), m_views.end(), p_view)); + if (m_views.empty()) { delete this; } } diff --git a/src/gui/nfgpanel.cc b/src/gui/nfgpanel.cc index 0dba2582b..10d61b1c8 100644 --- a/src/gui/nfgpanel.cc +++ b/src/gui/nfgpanel.cc @@ -434,8 +434,8 @@ END_EVENT_TABLE() gbtNfgPanel::gbtNfgPanel(wxWindow *p_parent, gbtGameDocument *p_doc) : wxPanel(p_parent, wxID_ANY), gbtGameView(p_doc), m_dominanceToolbar(new gbtStrategyDominanceToolbar(this, m_doc)), - m_tableWidget(new gbtTableWidget(this, wxID_ANY, m_doc)), - m_playerToolbar(new gbtTablePlayerToolbar(this, m_doc)) + m_playerToolbar(new gbtTablePlayerToolbar(this, m_doc)), + m_tableWidget(new gbtTableWidget(this, wxID_ANY, m_doc)) { auto *playerSizer = new wxBoxSizer(wxHORIZONTAL); playerSizer->Add(m_playerToolbar, 0, wxEXPAND, 0); diff --git a/src/gui/nfgtable.cc b/src/gui/nfgtable.cc index d4ba9e534..aaa1fd885 100644 --- a/src/gui/nfgtable.cc +++ b/src/gui/nfgtable.cc @@ -999,7 +999,7 @@ void gbtTableWidget::OnUpdate() { if (m_doc->NumPlayers() > m_rowPlayers.Length() + m_colPlayers.Length()) { for (int pl = 1; pl <= m_doc->NumPlayers(); pl++) { - if (!m_rowPlayers.Contains(pl) && !m_colPlayers.Contains(pl)) { + if (!contains(m_rowPlayers, pl) && !contains(m_colPlayers, pl)) { m_rowPlayers.push_back(pl); } } @@ -1060,7 +1060,7 @@ bool gbtTableWidget::ShowDominance() const { return m_nfgPanel->IsDominanceShown void gbtTableWidget::SetRowPlayer(int index, int pl) { - if (m_rowPlayers.Contains(pl)) { + if (contains(m_rowPlayers, pl)) { int oldIndex = m_rowPlayers.Find(pl); m_rowPlayers.Remove(oldIndex); if (index > oldIndex) { @@ -1108,7 +1108,7 @@ int gbtTableWidget::RowToStrategy(int player, int row) const void gbtTableWidget::SetColPlayer(int index, int pl) { - if (m_colPlayers.Contains(pl)) { + if (contains(m_colPlayers, pl)) { int oldIndex = m_colPlayers.Find(pl); m_colPlayers.Remove(oldIndex); if (index > oldIndex) { diff --git a/src/solvers/enummixed/enummixed.cc b/src/solvers/enummixed/enummixed.cc index 672c3cc58..6c48b50c8 100644 --- a/src/solvers/enummixed/enummixed.cc +++ b/src/solvers/enummixed/enummixed.cc @@ -35,13 +35,13 @@ List>> EnumMixedStrategySolution::GetCliques() c { if (m_cliques1.empty()) { // Cliques are generated on demand - int n = m_node1.size(); + auto n = m_node1.size(); if (m_node2.size() != n) { throw DimensionException(); } Array edgelist(n); - for (int i = 1; i <= n; i++) { + for (size_t i = 1; i <= n; i++) { edgelist[i].node1 = m_node1[i]; edgelist[i].node2 = m_node2[i]; } @@ -52,7 +52,7 @@ List>> EnumMixedStrategySolution::GetCliques() c } List>> solution; - for (int cl = 1; cl <= m_cliques1.size(); cl++) { + for (size_t cl = 1; cl <= m_cliques1.size(); cl++) { solution.push_back(List>()); for (int i = 1; i <= m_cliques1[cl].Length(); i++) { for (int j = 1; j <= m_cliques2[cl].Length(); j++) { @@ -131,9 +131,9 @@ EnumMixedStrategySolver::SolveDetailed(const Game &p_game) const Array vert1id(solution->m_v1); Array vert2id(solution->m_v2); - for (int i = 1; i <= vert1id.size(); vert1id[i++] = 0) + for (size_t i = 1; i <= vert1id.size(); vert1id[i++] = 0) ; - for (int i = 1; i <= vert2id.size(); vert2id[i++] = 0) + for (size_t i = 1; i <= vert2id.size(); vert2id[i++] = 0) ; int i = 0; diff --git a/src/solvers/enumpoly/behavextend.cc b/src/solvers/enumpoly/behavextend.cc index 03fa78b1e..769091a3d 100644 --- a/src/solvers/enumpoly/behavextend.cc +++ b/src/solvers/enumpoly/behavextend.cc @@ -58,7 +58,7 @@ void DeviationInfosets(List &answer, const BehaviorSupportProfile & } GameInfoset iset = child->GetInfoset(); if (iset->GetPlayer() == pl) { - int insert = 0; + size_t insert = 0; bool done = false; while (!done) { insert++; @@ -118,14 +118,14 @@ std::list DeviationSupports(const BehaviorSupportProfile BehaviorSupportProfile new_supp(big_supp); - for (int i = 1; i <= isetlist.size(); i++) { + for (size_t i = 1; i <= isetlist.size(); i++) { for (int j = 1; j < isetlist[i]->NumActions(); j++) { new_supp.RemoveAction(isetlist[i]->GetAction(j)); } new_supp.AddAction(isetlist[i]->GetAction(1)); active_act_no[i] = 1; - for (int k = 1; k < i; k++) { + for (size_t k = 1; k < i; k++) { if (isetlist[k]->Precedes(isetlist[i]->GetMember(1))) { if (isetlist[k]->GetAction(1)->Precedes(isetlist[i]->GetMember(1))) { new_supp.RemoveAction(isetlist[i]->GetAction(1)); @@ -146,11 +146,11 @@ std::list DeviationSupports(const BehaviorSupportProfile new_supp.RemoveAction(isetlist[iset_cursor]->GetAction(active_act_no[iset_cursor])); active_act_no[iset_cursor]++; new_supp.AddAction(isetlist[iset_cursor]->GetAction(active_act_no[iset_cursor])); - for (int k = iset_cursor + 1; k <= isetlist.size(); k++) { + for (size_t k = iset_cursor + 1; k <= isetlist.size(); k++) { if (active_act_no[k] > 0) { new_supp.RemoveAction(isetlist[k]->GetAction(1)); } - int h = 1; + size_t h = 1; bool active = true; while (active && h < k) { if (isetlist[h]->Precedes(isetlist[k]->GetMember(1))) { diff --git a/src/solvers/enumpoly/gameseq.h b/src/solvers/enumpoly/gameseq.h index ca2656ac6..cc20bd871 100644 --- a/src/solvers/enumpoly/gameseq.h +++ b/src/solvers/enumpoly/gameseq.h @@ -202,7 +202,7 @@ class GameSequenceForm { private: const GameSequenceForm *m_sfg; bool m_end{false}; - std::map m_indices; + std::map m_indices; public: using iterator_category = std::input_iterator_tag; diff --git a/src/solvers/enumpoly/gpartltr.imp b/src/solvers/enumpoly/gpartltr.imp index 18472ec43..d4be575f2 100644 --- a/src/solvers/enumpoly/gpartltr.imp +++ b/src/solvers/enumpoly/gpartltr.imp @@ -94,7 +94,7 @@ T TreeOfPartials::MaximalNonconstantContributionRECURSIVE( if (n->GetEldest() != nullptr) { Gambit::List> *> children = PartialTree.Children(n); - for (int i = 1; i <= children.size(); i++) { + for (size_t i = 1; i <= children.size(); i++) { wrtos[i]++; T increment = children[i]->GetData().Evaluate(p); @@ -130,7 +130,7 @@ T TreeOfPartials::MaximalNonconstantDifferenceRECURSIVE( if (n1->GetEldest() != nullptr && n2->GetEldest() != nullptr) { Gambit::List> *> children1 = PartialTree.Children(n1); Gambit::List> *> children2 = PartialTree.Children(n2); - for (int i = 1; i <= children1.size(); i++) { + for (size_t i = 1; i <= children1.size(); i++) { wrtos[i]++; T increment = children1[i]->GetData().Evaluate(p) - children2[i]->GetData().Evaluate(p); @@ -156,7 +156,7 @@ T TreeOfPartials::MaximalNonconstantDifferenceRECURSIVE( else if (n1->GetEldest() != nullptr && n2->GetEldest() == nullptr) { auto children1 = PartialTree.Children(n1); - for (int i = 1; i <= children1.size(); i++) { + for (size_t i = 1; i <= children1.size(); i++) { wrtos[i]++; T increment = children1[i]->GetData().Evaluate(p); @@ -181,7 +181,7 @@ T TreeOfPartials::MaximalNonconstantDifferenceRECURSIVE( else if (n1->GetEldest() == nullptr && n2->GetEldest() != nullptr) { auto children2 = PartialTree.Children(n2); - for (int i = 1; i <= children2.size(); i++) { + for (size_t i = 1; i <= children2.size(); i++) { wrtos[i]++; T increment = children2[i]->GetData().Evaluate(p); diff --git a/src/solvers/enumpoly/gpoly.h b/src/solvers/enumpoly/gpoly.h index 34f4479ea..47d9bbb38 100644 --- a/src/solvers/enumpoly/gpoly.h +++ b/src/solvers/enumpoly/gpoly.h @@ -270,7 +270,7 @@ template class gPoly { gPoly operator-() const { gPoly neg(*this); - for (int j = 1; j <= Terms.size(); j++) { + for (size_t j = 1; j <= Terms.size(); j++) { neg.Terms[j] = -Terms[j]; } return neg; @@ -284,7 +284,7 @@ template class gPoly { void operator-=(const gPoly &p) { gPoly neg = p; - for (int i = 1; i <= neg.Terms.size(); i++) { + for (size_t i = 1; i <= neg.Terms.size(); i++) { neg.Terms[i] = -neg.Terms[i]; } Terms = Adder(Terms, neg.Terms); @@ -318,7 +318,7 @@ template class gPoly { void operator*=(const gPoly &p) { Terms = Mult(Terms, p.Terms); } void operator*=(const T &val) { - for (int j = 1; j <= Terms.size(); j++) { + for (size_t j = 1; j <= Terms.size(); j++) { Terms[j] *= val; } } diff --git a/src/solvers/enumpoly/gpoly.imp b/src/solvers/enumpoly/gpoly.imp index c4010ab55..87420f7d9 100644 --- a/src/solvers/enumpoly/gpoly.imp +++ b/src/solvers/enumpoly/gpoly.imp @@ -44,8 +44,8 @@ List> gPoly::Adder(const List> &One, const List> & List> answer; - int i = 1; - int j = 1; + size_t i = 1; + size_t j = 1; while (i <= One.size() || j <= Two.size()) { if (i > One.size()) { answer.push_back(Two[j]); @@ -86,8 +86,8 @@ List> gPoly::Mult(const List> &One, const List> &T return answer; } - for (int i = 1; i <= One.size(); i++) { - for (int j = 1; j <= Two.size(); j++) { + for (size_t i = 1; i <= One.size(); i++) { + for (size_t j = 1; j <= Two.size(); j++) { gMono next = One[i] * Two[j]; if (answer.empty()) { @@ -177,12 +177,12 @@ template gPoly gPoly::PartialDerivative(int varnumber) const { gPoly newPoly(*this); - for (int i = 1; i <= newPoly.Terms.size(); i++) { + for (size_t i = 1; i <= newPoly.Terms.size(); i++) { newPoly.Terms[i] = gMono(newPoly.Terms[i].Coef() * (T)newPoly.Terms[i].ExpV()[varnumber], newPoly.Terms[i].ExpV().WithZeroExponent(varnumber)); } - int j = 1; + size_t j = 1; while (j <= newPoly.Terms.size()) { if (newPoly.Terms[j].Coef() == static_cast(0)) { newPoly.Terms.erase(std::next(newPoly.Terms.begin(), j - 1)); @@ -200,7 +200,7 @@ template gPoly gPoly::LeadingCoefficient(int varnumber) const gPoly newPoly(*this); int degree = DegreeOfVar(varnumber); newPoly.Terms = List>(); - for (int j = 1; j <= Terms.size(); j++) { + for (size_t j = 1; j <= Terms.size(); j++) { if (Terms[j].ExpV()[varnumber] == degree) { newPoly.Terms.push_back( gMono(Terms[j].Coef(), Terms[j].ExpV().WithZeroExponent(varnumber))); @@ -229,7 +229,7 @@ gPoly gPoly::TranslateOfMono(const gMono &m, const Vector &new_origi template gPoly gPoly::TranslateOfPoly(const Vector &new_origin) const { gPoly answer(GetSpace()); - for (int i = 1; i <= this->MonomialList().size(); i++) { + for (size_t i = 1; i <= this->MonomialList().size(); i++) { answer += TranslateOfMono(this->MonomialList()[i], new_origin); } return answer; diff --git a/src/solvers/enumpoly/gpolylst.imp b/src/solvers/enumpoly/gpolylst.imp index 4ee75839d..3fa88b7ac 100644 --- a/src/solvers/enumpoly/gpolylst.imp +++ b/src/solvers/enumpoly/gpolylst.imp @@ -45,7 +45,7 @@ Gambit::List InteriorSegment(const Gambit::List &p_list, int first, int la template gPolyList::gPolyList(const VariableSpace *sp, const Gambit::List *> &plist) : Space(sp) { - for (int ii = 1; ii <= plist.size(); ii++) { + for (size_t ii = 1; ii <= plist.size(); ii++) { auto *temp = new gPoly(*plist[ii]); List.push_back(temp); } @@ -54,7 +54,7 @@ gPolyList::gPolyList(const VariableSpace *sp, const Gambit::List *> template gPolyList::gPolyList(const VariableSpace *sp, const Gambit::List> &list) : Space(sp) { - for (int ii = 1; ii <= list.size(); ii++) { + for (size_t ii = 1; ii <= list.size(); ii++) { auto *temp = new gPoly(list[ii]); List.push_back(temp); } @@ -62,7 +62,7 @@ gPolyList::gPolyList(const VariableSpace *sp, const Gambit::List> &l template gPolyList::gPolyList(const gPolyList &lst) : Space(lst.Space) { - for (int ii = 1; ii <= lst.List.size(); ii++) { + for (size_t ii = 1; ii <= lst.List.size(); ii++) { auto *temp = new gPoly(*(lst.List[ii])); List.push_back(temp); } @@ -70,7 +70,7 @@ template gPolyList::gPolyList(const gPolyList &lst) : Space(lst. template gPolyList::~gPolyList() { - for (int ii = 1; ii <= List.size(); ii++) { + for (size_t ii = 1; ii <= List.size(); ii++) { delete List[ii]; } } @@ -82,12 +82,12 @@ template gPolyList::~gPolyList() template gPolyList &gPolyList::operator=(const gPolyList &rhs) { if (*this != rhs) { - for (int ii = List.size(); ii >= 1; ii--) { + for (size_t ii = List.size(); ii >= 1; ii--) { delete List[ii]; List.erase(std::next(List.begin(), ii - 1)); } - for (int ii = 1; ii <= rhs.List.size(); ii++) { + for (size_t ii = 1; ii <= rhs.List.size(); ii++) { auto *temp = new gPoly(*(rhs.List[ii])); List.push_back(temp); } @@ -103,7 +103,7 @@ template bool gPolyList::operator==(const gPolyList &rhs) const if (List.size() != rhs.List.size()) { return false; } - for (int j = 1; j <= List.size(); j++) { + for (size_t j = 1; j <= List.size(); j++) { if (*List[j] != *(rhs.List[j])) { return false; } @@ -165,7 +165,7 @@ template bool gPolyList::IsMultiaffine() const template Gambit::Vector gPolyList::Evaluate(const Gambit::Vector &v) const { Gambit::Vector answer(Length()); - for (int ii = 1; ii <= List.size(); ii++) { + for (size_t ii = 1; ii <= List.size(); ii++) { answer[ii] = List[ii]->Evaluate(v); } diff --git a/src/solvers/enumpoly/gtree.imp b/src/solvers/enumpoly/gtree.imp index eb1081136..f57629377 100644 --- a/src/solvers/enumpoly/gtree.imp +++ b/src/solvers/enumpoly/gtree.imp @@ -75,11 +75,11 @@ template void gTree::InsertAt(const T &t, gTreeNode *n) template void gTree::RecursiveCopy(gTreeNode *copyn, const gTreeNode *orign) { auto oldchildren = Children(orign); - for (int i = 1; i <= oldchildren.size(); i++) { + for (size_t i = 1; i <= oldchildren.size(); i++) { InsertAt(oldchildren[i]->data, copyn); } auto newchildren = Children(copyn); - for (int i = 1; i <= newchildren.size(); i++) { + for (size_t i = 1; i <= newchildren.size(); i++) { RecursiveCopy(newchildren[i], oldchildren[i]); } } @@ -160,7 +160,7 @@ bool gTree::SubtreesAreIsomorphic(const gTreeNode *lhs, const gTreeNode if (lchildren.size() != rchildren.size()) { return false; } - for (int i = 1; i <= lchildren.size(); i++) { + for (size_t i = 1; i <= lchildren.size(); i++) { if (!SubtreesAreIsomorphic(lchildren[i], rchildren[i])) { return false; } diff --git a/src/solvers/enumpoly/ndarray.h b/src/solvers/enumpoly/ndarray.h index 8f0b5c264..801e5b43c 100644 --- a/src/solvers/enumpoly/ndarray.h +++ b/src/solvers/enumpoly/ndarray.h @@ -61,11 +61,10 @@ template class NDArray { public: NDArray() : m_vector_dim(0) {} explicit NDArray(const Array &p_index_dim, int p_vector_dim) - : m_index_dim(p_index_dim), m_vector_dim(p_vector_dim), + : m_index_dim(p_index_dim), m_vector_dim(p_vector_dim), m_offsets(p_index_dim.size() + 1), m_storage( std::accumulate(m_index_dim.begin(), m_index_dim.end(), 1, std::multiplies()) * - m_vector_dim), - m_offsets(p_index_dim.size() + 1) + m_vector_dim) { m_offsets.front() = 1; std::partial_sum(m_index_dim.begin(), m_index_dim.end(), std::next(m_offsets.begin()), diff --git a/src/solvers/enumpoly/quiksolv.imp b/src/solvers/enumpoly/quiksolv.imp index 5791ba52c..7010616c8 100644 --- a/src/solvers/enumpoly/quiksolv.imp +++ b/src/solvers/enumpoly/quiksolv.imp @@ -451,15 +451,14 @@ void QuikSolv::FindRootsRecursion(Gambit::List> *rootl Gambit::Vector point = r.Center(); if (NewtonRootIsOnlyInRct(r, point)) { - int i; - for (i = NoEquations + 1; i <= System.Length(); i++) { + for (int i = NoEquations + 1; i <= System.Length(); i++) { if (TreesOfPartials[i].ValueOfRootPoly(point) < (double)0) { return; } } bool already_found = false; - for (i = 1; i <= rootlistptr->size(); i++) { + for (size_t i = 1; i <= rootlistptr->size(); i++) { if (fuzzy_equals(point, (*rootlistptr)[i])) { already_found = true; } diff --git a/src/solvers/linalg/lptab.imp b/src/solvers/linalg/lptab.imp index 231b8afeb..58c379300 100644 --- a/src/solvers/linalg/lptab.imp +++ b/src/solvers/linalg/lptab.imp @@ -170,7 +170,7 @@ template std::list> LPTableau::ReversePivots() if (!best_set.empty()) { ratio = solution[best_set[1]] / tmpcol[best_set[1]]; // find max ratio - for (int i = 2; i <= best_set.size(); i++) { + for (size_t i = 2; i <= best_set.size(); i++) { x = solution[best_set[i]] / tmpcol[best_set[i]]; if (this->GtZero(x - ratio)) { ratio = x; diff --git a/src/solvers/linalg/ludecomp.imp b/src/solvers/linalg/ludecomp.imp index 928cadcdf..1543ad449 100644 --- a/src/solvers/linalg/ludecomp.imp +++ b/src/solvers/linalg/ludecomp.imp @@ -320,7 +320,7 @@ void LUDecomposition::yLP_mult(const Vector &y, int j, Vector &ans) con template void LUDecomposition::LPd_Trans(Vector &d) const { Vector scratch(basis.First(), basis.Last()); - for (int j = 0; j < L.size(); j++) { + for (size_t j = 0; j < L.size(); j++) { LPd_mult(d, j, scratch); d = scratch; } diff --git a/src/solvers/linalg/vertenum.h b/src/solvers/linalg/vertenum.h index 32c9a99c8..aec008a7d 100644 --- a/src/solvers/linalg/vertenum.h +++ b/src/solvers/linalg/vertenum.h @@ -44,7 +44,7 @@ namespace Gambit::linalg { template class VertexEnumerator { private: bool mult_opt; - int depth{0}; + size_t depth{0}; int n; // N is the number of columns, which is the # of dimensions. int k; // K is the number of inequalities given. const Matrix &A; diff --git a/src/solvers/logit/efglogit.cc b/src/solvers/logit/efglogit.cc index 1e4a51bf0..16c0cd734 100644 --- a/src/solvers/logit/efglogit.cc +++ b/src/solvers/logit/efglogit.cc @@ -60,7 +60,7 @@ MixedBehaviorProfile PointToProfile(const Game &p_game, const Vector PointToLogProfile(const Game &p_game, const Vector &p_point) { LogBehavProfile profile(p_game); - for (int i = 1; i <= profile.BehaviorProfileLength(); i++) { + for (size_t i = 1; i <= profile.BehaviorProfileLength(); i++) { profile.SetLogProb(i, p_point[i]); } return profile; @@ -69,7 +69,7 @@ LogBehavProfile PointToLogProfile(const Game &p_game, const Vector ProfileToPoint(const LogitQREMixedBehaviorProfile &p_profile) { Vector point(p_profile.size() + 1); - for (int i = 1; i <= p_profile.size(); i++) { + for (size_t i = 1; i <= p_profile.size(); i++) { point[i] = log(p_profile[i]); } point.back() = p_profile.GetLambda(); diff --git a/src/solvers/logit/nfglogit.cc b/src/solvers/logit/nfglogit.cc index bda5bb8ca..5cebb77d4 100644 --- a/src/solvers/logit/nfglogit.cc +++ b/src/solvers/logit/nfglogit.cc @@ -43,7 +43,7 @@ MixedStrategyProfile PointToProfile(const Game &p_game, const Vector ProfileToPoint(const LogitQREMixedStrategyProfile &p_profile) { Vector point(p_profile.size() + 1); - for (int i = 1; i <= p_profile.size(); i++) { + for (size_t i = 1; i <= p_profile.size(); i++) { point[i] = log(p_profile[i]); } point.back() = p_profile.GetLambda(); diff --git a/src/solvers/nashsupport/nfgsupport.cc b/src/solvers/nashsupport/nfgsupport.cc index f5260a5be..a58ad338f 100644 --- a/src/solvers/nashsupport/nfgsupport.cc +++ b/src/solvers/nashsupport/nfgsupport.cc @@ -63,7 +63,7 @@ class CartesianRange { iterator &operator++() { - for (int i = 1; i <= m_sizes.size(); i++) { + for (size_t i = 1; i <= m_sizes.size(); i++) { if (++m_indices[i] <= m_sizes[i]) { return *this; } diff --git a/src/solvers/simpdiv/simpdiv.cc b/src/solvers/simpdiv/simpdiv.cc index 7ab03b767..7ce370b5a 100644 --- a/src/solvers/simpdiv/simpdiv.cc +++ b/src/solvers/simpdiv/simpdiv.cc @@ -37,7 +37,7 @@ template class PVector { : m_values(std::accumulate(p_shape.begin(), p_shape.end(), 0)), m_offsets(p_shape.size()), m_shape(p_shape) { - for (int index = 0, i = 1; i <= m_shape.size(); i++) { + for (size_t index = 0, i = 1; i <= m_shape.size(); i++) { m_offsets[i] = index; index += m_shape[i]; } @@ -107,7 +107,7 @@ Rational NashSimpdivStrategySolver::Simplex(MixedStrategyProfile &y, RectArray labels(y.MixedProfileLength(), 2), pi(y.MixedProfileLength(), 2); PVector U(nstrats), TT(nstrats); PVector ab(nstrats), besty(nstrats), v(nstrats); - for (int i = 1; i <= v.size(); i++) { + for (size_t i = 1; i <= v.size(); i++) { v[i] = y[i]; } besty = static_cast &>(y); @@ -399,7 +399,7 @@ void NashSimpdivStrategySolver::getY(const State &state, MixedStrategyProfile &pi, int k) { x = static_cast &>(v); - for (size_t j = 1; j <= x.GetGame()->NumPlayers(); j++) { + for (int j = 1; j <= x.GetGame()->NumPlayers(); j++) { GamePlayer player = x.GetGame()->GetPlayer(j); for (size_t h = 1; h <= player->GetStrategies().size(); h++) { if (TT(j, h) == 1 || U(j, h) == 1) { diff --git a/src/tools/enummixed/enummixed.cc b/src/tools/enummixed/enummixed.cc index c98c4eabe..cefaaf9d6 100644 --- a/src/tools/enummixed/enummixed.cc +++ b/src/tools/enummixed/enummixed.cc @@ -35,8 +35,8 @@ template void PrintCliques(const List>> &p_cliques, std::shared_ptr> p_renderer) { - for (int cl = 1; cl <= p_cliques.size(); cl++) { - for (int i = 1; i <= p_cliques[cl].size(); i++) { + for (size_t cl = 1; cl <= p_cliques.size(); cl++) { + for (size_t i = 1; i <= p_cliques[cl].size(); i++) { p_renderer->Render(p_cliques[cl][i], "convex-" + lexical_cast(cl)); } } diff --git a/src/tools/enumpoly/enumpoly.cc b/src/tools/enumpoly/enumpoly.cc index 2f5242f50..412b3db71 100644 --- a/src/tools/enumpoly/enumpoly.cc +++ b/src/tools/enumpoly/enumpoly.cc @@ -66,7 +66,7 @@ void PrintProfile(std::ostream &p_stream, const std::string &p_label, const MixedStrategyProfile &p_profile) { p_stream << p_label; - for (int i = 1; i <= p_profile.MixedProfileLength(); i++) { + for (size_t i = 1; i <= p_profile.MixedProfileLength(); i++) { p_stream.setf(std::ios::fixed); p_stream << ',' << std::setprecision(g_numDecimals) << p_profile[i]; } @@ -93,7 +93,7 @@ void PrintProfile(std::ostream &p_stream, const std::string &p_label, const MixedBehaviorProfile &p_profile) { p_stream << p_label; - for (int i = 1; i <= p_profile.BehaviorProfileLength(); i++) { + for (size_t i = 1; i <= p_profile.BehaviorProfileLength(); i++) { p_stream.setf(std::ios::fixed); p_stream << "," << std::setprecision(g_numDecimals) << p_profile[i]; } diff --git a/src/tools/gt/nfggt.cc b/src/tools/gt/nfggt.cc index 46025f35f..b126843fd 100644 --- a/src/tools/gt/nfggt.cc +++ b/src/tools/gt/nfggt.cc @@ -30,7 +30,7 @@ List> ReadStrategyPerturbations(const Game &p_game, List> profiles; while (!p_stream.eof() && !p_stream.bad()) { MixedStrategyProfile p(p_game->NewMixedStrategyProfile(0.0)); - for (int i = 1; i <= p.MixedProfileLength(); i++) { + for (size_t i = 1; i <= p.MixedProfileLength(); i++) { if (p_stream.eof() || p_stream.bad()) { break; } diff --git a/src/tools/liap/liap.cc b/src/tools/liap/liap.cc index ba41d0f23..912788e87 100644 --- a/src/tools/liap/liap.cc +++ b/src/tools/liap/liap.cc @@ -64,7 +64,7 @@ List> ReadStrategyProfiles(const Game &p_game, std: List> profiles; while (!p_stream.eof() && !p_stream.bad()) { MixedStrategyProfile p(p_game->NewMixedStrategyProfile(0.0)); - for (int i = 1; i <= p.MixedProfileLength(); i++) { + for (size_t i = 1; i <= p.MixedProfileLength(); i++) { if (p_stream.eof() || p_stream.bad()) { break; } @@ -97,7 +97,7 @@ List> ReadBehaviorProfiles(const Game &p_game, std: List> profiles; while (!p_stream.eof() && !p_stream.bad()) { MixedBehaviorProfile p(p_game); - for (int i = 1; i <= p.BehaviorProfileLength(); i++) { + for (size_t i = 1; i <= p.BehaviorProfileLength(); i++) { if (p_stream.eof() || p_stream.bad()) { break; } @@ -214,7 +214,7 @@ int main(int argc, char *argv[]) starts = RandomStrategyProfiles(game, numTries); } - for (int i = 1; i <= starts.size(); i++) { + for (size_t i = 1; i <= starts.size(); i++) { std::shared_ptr> renderer( new MixedStrategyCSVRenderer(std::cout, numDecimals)); @@ -238,7 +238,7 @@ int main(int argc, char *argv[]) starts = RandomBehaviorProfiles(game, numTries); } - for (int i = 1; i <= starts.size(); i++) { + for (size_t i = 1; i <= starts.size(); i++) { std::shared_ptr> renderer( new BehavStrategyCSVRenderer(std::cout, numDecimals)); LiapBehaviorSolve(starts[i], maxregret, maxitsN, diff --git a/src/tools/logit/logit.cc b/src/tools/logit/logit.cc index 203c51de2..e1f383997 100644 --- a/src/tools/logit/logit.cc +++ b/src/tools/logit/logit.cc @@ -66,7 +66,7 @@ void PrintHelp(char *progname) // bool ReadProfile(std::istream &p_stream, MixedStrategyProfile &p_profile) { - for (int i = 1; i <= p_profile.MixedProfileLength(); i++) { + for (size_t i = 1; i <= p_profile.MixedProfileLength(); i++) { if (p_stream.eof() || p_stream.bad()) { return false; } diff --git a/src/tools/simpdiv/nfgsimpdiv.cc b/src/tools/simpdiv/nfgsimpdiv.cc index 159d90ec9..9974b5927 100644 --- a/src/tools/simpdiv/nfgsimpdiv.cc +++ b/src/tools/simpdiv/nfgsimpdiv.cc @@ -36,7 +36,7 @@ List> ReadProfiles(const Game &p_game, std::istre List> profiles; while (!p_stream.eof() && !p_stream.bad()) { MixedStrategyProfile p(p_game->NewMixedStrategyProfile(Rational(0))); - for (int i = 1; i <= p.MixedProfileLength(); i++) { + for (size_t i = 1; i <= p.MixedProfileLength(); i++) { if (p_stream.eof() || p_stream.bad()) { break; }