Program Listing for File ipg.h

Return to documentation for file (include/games/ipg.h)

/* #############################################
 *             This file is part of
 *                    ZERO
 *
 *             Copyright (c) 2020
 *     Released under the Creative Commons
 *         CC BY-NC-SA 4.0 License
 *
 *              Find out more at
 *        https://github.com/ds4dm/ZERO
 * #############################################*/


#pragma once
#include "zero.h"
#include <armadillo>
#include <gurobi_c++.h>
#include <iostream>
#include <memory>
#include <set>
#include <string>

namespace Data::IPG {

  enum class Algorithms {
     CutAndPlay,
     ZERORegrets
  };

  enum class CutsAggressiveness {
     NotEvenTry,
     NoThanks,
     KeepItCool,
     Truculent
  };
  enum class Objectives {
     Feasibility,
     Quadratic,
     Linear,
     ZERORegrets_SocialCost,
     ZERORegrets_PlayerOne
  };

  class DataObject : public ZEROAlgorithmData {
  public:
     Attr<Data::IPG::CutsAggressiveness> CutAggressiveness = {
          Data::IPG::CutsAggressiveness::KeepItCool};
     Attr<Data::IPG::Algorithms> Algorithm = {
          Data::IPG::Algorithms::CutAndPlay};
     Attr<Data::LCP::Algorithms> LCPSolver;
     Attr<Data::IPG::Objectives> Objective = {
          Data::IPG::Objectives::Linear};
     Attr<std::vector<std::pair<std::string, int>>>
          Cuts;

     Attr<double> Presolve = {true};
     DataObject() : LCPSolver{static_cast<Data::LCP::Algorithms>(0)} {};
  };
} // namespace Data::IPG


namespace Game {

  class IPG : public AbstractGame<Data::IPG::DataObject> {
  protected: // Datafields
     std::vector<std::shared_ptr<MathOpt::IP_Param>>
          PlayersIP{};

     std::vector<unsigned int> PlayerVariables{};


     bool                   Finalized{false};
     std::vector<arma::vec> Solution;
     double                 SocialWelfare;

  private:
     std::shared_ptr<Algorithms::IPG::Algorithm> Algorithm{};


  protected:
     virtual void preFinalize() = 0;
     virtual void postFinalize() = 0;

  public: // functions
     friend class Algorithms::IPG::Algorithm;
     friend class Algorithms::IPG::CutAndPlay;
     friend class Algorithms::IPG::ZERORegrets;
     void finalize();
     IPG(GRBEnv *env) { this->Env = env; };
     IPG(GRBEnv *env, std::vector<std::shared_ptr<MathOpt::IP_Param>> players);

     void findNashEq() override;
     bool isSolved(double tol = 1e-5) const override;
     bool isPureStrategy(double tol = 1e-5) const override;


     std::vector<arma::vec> getX() const { return this->Solution; }

     /***
      * @brief Gets the SocialWelfare associated to the incumbent solution
      * @return The payoff value
      */
     double getSocialWelfare() const { return this->SocialWelfare; }

     ZEROStatistics<Data::IPG::DataObject> getStatistics() const { return this->Stats; }

     void setAlgorithm(Data::IPG::Algorithms algorithm) {
        this->Stats.AlgorithmData.Algorithm = algorithm;
     }

     void setPresolve(bool value) {
        this->Stats.AlgorithmData.Presolve=value;
     }
     void setLCPAlgorithm(const Data::LCP::Algorithms algo) {
        this->Stats.AlgorithmData.LCPSolver.set(algo);
     }
     void setGameObjective(const Data::IPG::Objectives obj) {
        this->Stats.AlgorithmData.Objective.set(obj);
     }
     void setCutsAggressiveness(const Data::IPG::CutsAggressiveness aggressiveness) {
        this->Stats.AlgorithmData.CutAggressiveness.set(aggressiveness);
     }
  };


} // namespace Game
namespace std {
  string to_string(Data::IPG::Algorithms al);
  string to_string(Data::IPG::Objectives ob);
  string to_string(Data::IPG::CutsAggressiveness ct);

}; // namespace std

#include "algorithms/IPG/ipg_algorithms.h"
#include "interfaces/ipg_models.h"