Unrecognized function or variable 'yalmip'.
    43 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
 matlab should known  sdpvar  in the code becuse if i used help it give me the meaning of it but it said instead 
Unrecognized function or variable 'yalmip'.
Error in sdpvar (line 518)
[mt,variabletype,hashed_monoms,current_hash] = yalmip('monomtable');
% Define the partially specified Euclidean distance matrix
D = [0 1 0 3;     1 0 2 0;     0 2 0 0;     3 0 0 0];
% Define the size of the matrix
n = size(D, 1);
% Define the optimization variables
X = sdpvar(n, n);
% Set up the optimization problem
Constraints = [X == semidefinite(n), diag(X) == zeros(n, 1), X >= 0];
Objective = sum(sum((X - D).^2));
Options = sdpsettings('solver', 'mosek');
% Solve the optimization problem
optimize(Constraints, Objective, Options);
% Extract the completed Euclidean distance matrix
D_complete = value(X);
4 commentaires
Réponses (2)
  Sachin
    
 le 13 Mar 2023
        As per my understanding you are facing issue in ‘yalmip’ implementation. Referring the following information might be of good help to you assuming that you are using MATLAB R2022b.
- Check if you have installed ‘yalmip’ in your system by following command in MATLAB.
     V = yalmip('version'); % to check version of 'yalmip'
         2. If You have not added the path after downloading the zip file.
- Download the ‘yalmip’ https://yalmip.github.io/download/
- To add path, open ‘yalmip’ folder in your MATLAB.
- Right click on the folder, you will see add to path.
You can refer the following information to know more about add path.
0 commentaires
  mouhcine
 le 17 Juin 2025
        %% Initialisation des données
clc; clear; close all;
% 1. Données des clients (5 clients + dépôt)
clients = [
    0   0    0    0    0   ; % Dépôt (id, x, y, début fenêtre, fin fenêtre)
    1   2    3    8    10  ; % Client 1
    2   1    5    9    12  ; % Client 2
    3   4    2    10   14  ; % Client 3
    4   3    6    11   15  ; % Client 4
    5   5    1    13   17  ; % Client 5
];
% Temps de service (minutes)
s = [0; 15; 10; 20; 10; 15]; 
% Demandes (kg)
q_demand = [0; 10; 8; 12; 5; 7];
% 2. Calcul des distances
n_clients = size(clients,1);
distances = zeros(n_clients,n_clients);
for i = 1:n_clients
    for j = 1:n_clients
        distances(i,j) = norm(clients(i,2:3) - clients(j,2:3));
    end
end
% 3. Données des camions (5 véhicules)
camions = [
    200  40  0.30  20 ; 
    300  45  0.35  30 ; 
    150  50  0.25  15 ; 
    250  35  0.40  25 ; 
    350  40  0.45  35 ; 
];
%% Modélisation YALMIP
n_camions = size(camions,1);
% Variables
x = binvar(n_clients,n_clients,n_camions,'full'); % Trajets
t = sdpvar(n_clients,1); % Temps d'arrivée
y = binvar(n_camions,1); % Camion utilisé
% Contraintes
C = [];
% Chaque client visité une fois (sauf dépôt)
for i = 2:n_clients
    C = [C, sum(sum(x(i,:,:),3) == 1];
end
% Équilibre de flux
for k = 1:n_camions
    for p = 1:n_clients
        C = [C, sum(x(:,p,k)) == sum(x(p,:,k))];
    end
end
% Capacité
for k = 1:n_camions
    C = [C, sum(q_demand'.*squeeze(x(2:end,:,k))) <= camions(k,1)];
end
% Fenêtres temporelles
for i = 2:n_clients
    C = [C, clients(i,4) <= t(i) <= clients(i,5)];
end
% Calcul des temps
M = 24; % Big-M
for k = 1:n_camions
    for i = 1:n_clients
        for j = 1:n_clients
            if i ~= j
                C = [C, t(j) >= t(i) + s(i)/60 + distances(i,j)/camions(k,2) - M*(1-x(i,j,k))];
            end
        end
    end
end
% Activation camions
for k = 1:n_camions
    C = [C, sum(x(1,:,k)) == y(k)];
end
%% Objectifs
cout_total = 0;
for k = 1:n_camions
    cout_total = cout_total + sum(sum(distances.*camions(k,3).*x(:,:,k))) + camions(k,4)*y(k);
end
temps_total = max(t(2:end) + s(2:end)/60);
%% Résolution
options = sdpsettings('solver','gurobi','verbose',1);
optimize(C, cout_total + 0.1*temps_total, options); % Pondération arbitraire
%% Affichage des résultats
if value(cout_total) > 0
    disp('=== Solution trouvée ===');
    disp(['Coût total: ', num2str(value(cout_total)), ' €']);
    disp(['Temps total: ', num2str(value(temps_total)), ' heures']);
    % Visualisation des tournées...
else
    disp('Aucune solution trouvée');
end
1 commentaire
  Walter Roberson
      
      
 le 17 Juin 2025
				C = [C, sum(sum(x(i,:,:),3) == 1];
%          1   2 3     2  1
The digits are the nesting level "after" the character above in the expression.
Notice that at the end, the active nesting level is 1, instead of 0. You are missing a ) somewhere in the expression. You probably wanted
C = [C, sum(sum(x(i,:,:),3)) == 1];
or more simply,
C = [C, sum(x(i,:,:),"all") == 1];
Voir également
Catégories
				En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





