Error (Bad suffix .solver -- solve_result cannot have a suffix)

Hello, I’m a student working on an assignment using the AMPL application, I’m new to using AMPL.
I hope someone can help me.
Here is the error that occurred in my code:

ampl: include tsp_run.run;
CPLEX 22.1.1.0: optimal integer solution; objective 402.5
24 MIP simplex iterations
0 branch-and-bound nodes
Global optimal solution found.
Objective value:	402.5000
Objective bound:	402.5000
Infeasibilities:	0.000000
Extended solver steps:	0

tsp_run.run, line 17 (offset 503):
	Bad suffix .solver -- solve_result cannot have a suffix.
context:  printf "Total solver iterations:\t%d\n",  >>> solve_result.solver. <<< iter;

Here are all the files I used,
File tsp_model. mod

param N;
param DIST{i in 1..N, j in 1..N};

# Set variabel biner X[i,j] yang menunjukkan apakah kota i terhubung langsung ke kota j dalam tur
var X{1..N, 1..N} binary;

# Define variable U[i] untuk merepresentasikan urutan kota dalam tur
var U{1..N} >= 1, <= N;

# Menggunakan perintah minimize untuk mendefinisikan tujuan optimasi
minimize Total_Distance: sum{i in 1..N, j in 1..N} DIST[i,j] * X[i,j];

# Setelah mengunjungi kota, kita harus kembali ke kota awal (kota 1)
subject to Return_to_Start {i in 1..N: i != 1}:
    sum{j in 1..N: j != i} X[i,j] = 1;

# Setiap kota hanya bisa dikunjungi sekali dalam tur
subject to Visit_Once {j in 1..N: j != 1}:
    sum{i in 1..N: i != j} X[i,j] = 1;

# Subtour elimination constraints
subject to Subtour_Elimination{i in 2..N, j in 2..N: j >= 1}:
    U[i] - U[j] + (N - 1) * X[i,j] <= N - 2;

# Menyatakan bahwa kota 1 adalah kota awal dan akhir tur
subject to Start_End {i in 2..N}:
    U[i] <= N - 1 - (N - 2) * X[1,i];
subject to Start_End_Reverse {i in 2..N}:
    U[i] >= 1 + (N - 2) * X[i,1];

File tsp_data. dat

param N := 5;

param DIST: 1 2 3 4 5 :=
1   0  123  159  157  180
2 123    0   70   68   88
3 159   70    0  9.5   25
4 157   68  9.5    0  32.4
5 180   88   25 32.2    0;

File tsp_run. run

# Load model and data
model tsp_model.mod;
data tsp_data.dat;

# Using CPLEX solver to solve the TSP model
option solver cplex;
solve;

# Display optimal results
printf "Global optimal solution found.\n";
printf "Objective value:\t%.4f\n", Total_Distance;
printf "Objective bound:\t%.4f\n", Total_Distance;
printf "Infeasibilities:\t%.6f\n", 0.0;
printf "Extended solver steps:\t%d\n", 0;

# Access solver statistics and display total iterations
printf "Total solver iterations:\t%d\n", solve_result.solver.iter;

# Display variable U values
printf "\nVariable\tValue\n";
for {i in 1..N} {
    printf "U(%d)\t\t%.6f\n", i, U[i];
}

File:
tsp_data.dat (178 Bytes)
Uploading: tsp_model.mod…
tsp_run.run (652 Bytes)

AMPL is rejecting this statement in tsp_run.run:

printf "Total solver iterations:\t%d\n", solve_result.solver.iter;

with this error message:

tsp_run.run, line 17 (offset 503):
	Bad suffix .solver -- solve_result cannot have a suffix.

You are getting this error because solve_result.solver.iter is not a correct expression in AMPL, and therefore AMPL cannot process it properly.

In fact, there is no expression in AMPL that gives the number of iterations in CPLEX. However, the built-in AMPL expression solve_message contains a string that includes the number of iterations. In your example, the command print solve_message; would give this result:

CPLEX 22.1.1.0: optimal integer solution; objective 402.5
24 MIP simplex iterations
0 branch-and-bound nodes

You can use AMPL string functions to extract information from solve_message. For example, the number of simplex iterations is given by this expression,

num0(substr(solve_message,match(solve_message,"\n")+1))

and the number of branch-and-bound nodes by

num0(substr(solve_message,match(solve_message,"s\n")+2))

(\n represents a new-line character.) To learn how these expressions work, see Section A.4.2 Strings and regular expressions in the AMPL book.