How can I find the vector that simultaneously maximizes my two functions?

1 次查看(过去 30 天)
Hi everyone, I am new in using matlab, I am using it for my own work, this is the Code:
fa=0:1; %[1:100] ho cambiato per uguagliare dimensione vettori
fh=0:4;
% Frequenze di viaggio
%Fa=1:4;
Fa=1;
%Fh=1:4; %[1:10] ho cambiato per uguagliare dimensione vettori
Fh=1;
%Tempi di viaggio
Ta=2;
Th=1;
diffTemp=Ta-Th;
%VOT e costi
lVOT=1;
uVOT=0;
diffVOT=uVOT-lVOT;
ca=1;
Ca=1;
ch=0;
Ch=0;
%for i=2:length(fa);
% j=2:length(fh);
% Pa(i,j) = (fa(i)./diffVOT)*((fh(j)-fa(i))/diffTemp)-lVOT-Fa.*ca-Ca
%end
% Calcolo di Pa senza l'uso di cicli
%Pa = (fa./diffVOT).*((fh - fa)./ diffTemp) - lVOT - (Fa.*ca) - Ca
for i=1:length(fa)
for j=1:length(fh)
Pa(i,j) = (i/diffVOT).*(((j-i)/diffTemp) - lVOT) - (Fa*ca) - Ca
Ph(j,i) = ((j/diffVOT).*(uVOT - ((j-i)/diffTemp))) - (Fh*ch) - Ch
end
end
In this way i'm able to calculate the value of the function for the different combinations of (fa,fh), but my problem consists in the following: I have two players "a" and "h", each of them has its own function that expresses the profit "Pa , Ph"; all values in the function are constants, except for "fa" and "fh" which are expressed as vectors of different sizes.
I need to find an x(fa*,fh*) vector made from the value of "fa" and "fh" which simultaneously maximizes the "Pa" and "Ph" profit functions of both players, but I don’t know how to implement this on matlab.
Can anyone help me?

采纳的回答

Hassaan
Hassaan 2024-2-23
编辑:Hassaan 2024-2-23
% Clear workspace, close all figures, and clear command window
clear; close all; clc;
% Define constants
diffTemp = 2 - 1; % Ta - Th, example values
lVOT = 1;
uVOT = 0;
diffVOT = uVOT - lVOT;
Fa = 1;
Fh = 1;
ca = 1;
Ca = 1;
ch = 0;
Ch = 0;
% Define optimization variables
fa = optimvar('fa', 'LowerBound', 0, 'UpperBound', 1); % Adjust bounds as necessary
fh = optimvar('fh', 'LowerBound', 0, 'UpperBound', 4); % Adjust bounds as necessary
% Define the objective functions using anonymous functions
objPa = @(fa, fh) (fa./diffVOT).*((fh - fa)./ diffTemp) - lVOT - (Fa.*ca) - Ca;
objPh = @(fa, fh) ((fh./diffVOT).*(uVOT - ((fh - fa)./ diffTemp))) - (Fh.*ch) - Ch;
% Combine the objectives into a single function (for demonstration)
totalObjective = objPa(fa, fh) + objPh(fa, fh);
% Create the optimization problem
prob = optimproblem('Objective', totalObjective, 'ObjectiveSense', 'maximize');
% Solve the optimization problem
[sol, fval, exitflag, output] = solve(prob);
% Display the solution
disp('Solution:');
disp(sol);
fprintf('Combined Profit: %f\n', fval);
fprintf('Exit Flag: %d\n', exitflag);
fprintf('Solver Output:\n');
disp(output);
  • The interaction between two players into a single optimization problem for illustrative purposes. In real-world scenarios, especially in game theory, interactions might require more sophisticated approaches to find equilibria or optimal strategies.
  • The effectiveness and applicability of combining objectives like this depend on the nature of the interaction between fa and fh. In cases where their interests are opposed, a more nuanced approach to find a Nash equilibrium or Pareto optimality might be necessary.
  • The solve function automatically selects an appropriate solver based on the problem type. For more control or for large-scale problems, consider specifying solver options.
Note:
  • It's an initial attempt and may need adjustment as per your requirements.
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  1 个评论
Guglielmo
Guglielmo 2024-2-23
Thx for the help, i'm doing this work for my Master Degree Thesys, i need to find the Generalized Nash Eq (GNE) in this game, where the competition is between 2 different mode of transport (a=air, h=high speed rail) for a common path.
I'm quite new to Game Theory and Matlab, and for that reason i'm finding problems, so thanks a lot for ur time

请先登录,再进行评论。

更多回答(1 个)

Torsten
Torsten 2024-2-23
移动:Torsten 2024-2-23
Usually, you can't find a vector that maximizes both of your functions simultaneously. You can compute the pareto-front for your two functions:

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by