Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions src/solvers/hp/hp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,33 @@ HPStrategySolve(const MixedStrategyProfile<double> &p_prior)
std::list<MixedStrategyProfile<double>> equilibria;

HPEquationSystem system(p_prior);
Vector<double> x = system.ComputeInitialPoint();

const PathTracer tracer;
double omega = 1.0;
Vector<double> x;
double p_omega = 1.0;

auto termination_condition = [](const Vector<double> &point) { return point[1] >= 1.5; };
auto criterion_function = [](const Vector<double> &point,
const Vector<double> &tangent) -> double { return point[1] - 1.0; };
const double t_target = 1.0;
const double t_tol = 0.5;

auto criterion_function = [t_target](const Vector<double> &point,
const Vector<double> &tangent) -> double {
return point[1] - t_target;
};

x = system.ComputeInitialPoint();

auto termination_condition = [t_target, t_tol](const Vector<double> &point) {
return (point[1] >= t_target + t_tol);
};

const TracePathResult result = tracer.TracePath(
[&system](const Vector<double> &point, Vector<double> &lhs) { system.GetValue(point, lhs); },
[&system](const Vector<double> &point, Matrix<double> &jac) {
system.GetJacobian(point, jac);
},
x, omega, termination_condition,
x, p_omega, termination_condition,
[&system](const Vector<double> &point) {
std::cout << "[Path Tracer Step] t = " << point[1];
std::cout << " | Alfas: ";
for (size_t i = 2; i <= 5; ++i) {
std::cout << point[i] << " ";
}
std::cout << "| Mu: " << point[6] << " " << point[7] << std::endl;

std::cout << "[Path Tracer Step] t = " << point[1] << std::endl;
std::cout << "Full point vector in probabilities: ";
Vector<double> prob_vector = system.ExtractEquilibrium(point).GetProbVector();
for (size_t i = 1; i <= prob_vector.size(); ++i) {
Expand All @@ -66,7 +70,23 @@ HPStrategySolve(const MixedStrategyProfile<double> &p_prior)
},
criterion_function);

equilibria.push_back(system.ExtractEquilibrium(x));
const MixedStrategyProfile<double> eq_profile = system.ExtractEquilibrium(x);

equilibria.push_back(eq_profile);

// Check that the profile is an equilibrium taking into account how far we are from the target t
// value
const double delta = std::abs(t_target - x[1]);
const double scale = p_prior.GetGame()->GetMaxPayoff() - p_prior.GetGame()->GetMinPayoff();
const double max_regret = eq_profile.GetMaxRegret();
// error tolerance <= delta * scale
const double error_tolerance =
(delta * scale) + 1e-6; // Add a small epsilon to account for numerical errors

// If it is not an equilibrium, return an empty list
if (max_regret > error_tolerance) {
return {};
}
return equilibria;
}
} // namespace Gambit
Loading