Hi Zhou,
I understand it can get frustrating. MATLAB getting stuck while using AMPL's LOQO solver, can be due to several reasons. Here are some common issues and troubleshooting steps to help resolve the problem-
Common Issues-
- Infinite Loop or Long Computation:
- Numerical Instability or poorly scaled problem
- MATLAB-AMPL Interface Issues
Troubleshooting Steps-
1. Interrupt Execution: Press Ctrl+C in the MATLAB Command Window. This often stops the current operation and returns control to you.
2. Set Solver Options: Set options to limit the number of iterations or the computation time. Do this by modifying the run file or setting options directly in the AMPL model:
fid = fopen('run.run', 'w');
fprintf(fid, 'model model.mod;\n');
fprintf(fid, 'data data.dat;\n');
fprintf(fid, 'option solver loqo;\n');
fprintf(fid, 'option loqo_options ''max_iter=1000 timelimit=300'';\n');
fprintf(fid, 'solve;\n');
fprintf(fid, 'display _varname, _var, _conname, _con;\n');
3. Check Problem Feasibility: Check if the problem is feasible, can use feasibility checks and diagnostic tools provided by AMPL:
fid = fopen('run.run', 'w');
fprintf(fid, 'model model.mod;\n');
fprintf(fid, 'data data.dat;\n');
fprintf(fid, 'option solver loqo;\n');
fprintf(fid, 'solve;\n');
fprintf(fid, 'display _varname, _var, _conname, _con;\n');
fprintf(fid, 'display solve_result_num, solve_message;\n');
4. Use MATLAB's Debugging Tools: MATLAB provides several debugging tools that can help identify where the problem is:
- Breakpoints: Set breakpoints in code to pause execution and inspect variables.
- Step Through Code: Use the "Step" buttons in the MATLAB Editor to execute code line by line.
Example of Using dbstop: Set MATLAB to stop execution when an error occurs using the “dbstop” command:
Example of Debugging Infinite Loop: Here's an example of how to debug an infinite loop:
disp(['Iteration: ', num2str(i)]);
Please refer to the following documentation links-
Hope it helps!
Best Regards,
Simar