# Error (Bad suffix .solver -- solve\_result cannot have a suffix)

**URL:** <https://discuss.ampl.com/t/error-bad-suffix-solver-solve-result-cannot-have-a-suffix/661>\
**Category:** Support\
**Tags:** errors-and-messages\
**Created:** [July 29, 2023, 11:31am UTC](https://discuss.ampl.com/t/error-bad-suffix-solver-solve-result-cannot-have-a-suffix/661 "2023-07-29T11:31:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anwar\_Safii](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/anwar_safii/32/355_2.png) [@Anwar\_Safii](https://discuss.ampl.com/u/Anwar_Safii)\
**Post date:** [July 29, 2023, 11:31am UTC](https://discuss.ampl.com/t/error-bad-suffix-solver-solve-result-cannot-have-a-suffix/661/1 "2023-07-29T11:31:30Z")

</div>

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:

```auto
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

```auto
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

```auto
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

```auto
# 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](https://discuss.ampl.com/uploads/short-url/nZTUWiZWlcxf9PoETkHmkVDEIh2.dat) (178 Bytes)  
Uploading: tsp\_model.mod…  
[tsp\_run.run](https://discuss.ampl.com/uploads/short-url/mYiN4FTOVwtHhBF3H22YihqSBR7.run) (652 Bytes)

---

<div class="post-metadata">

**Author:** ![4er](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/4er/32/530_2.png) [@4er](https://discuss.ampl.com/u/4er)\
**Post date:** [July 29, 2023, 6:58pm UTC](https://discuss.ampl.com/t/error-bad-suffix-solver-solve-result-cannot-have-a-suffix/661/2 "2023-07-29T18:58:51Z")

</div>

AMPL is rejecting this statement in tsp\_run.run:

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

```

with this error message:

```auto
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:

```auto
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,

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

```

and the number of branch-and-bound nodes by

```auto
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](https://ampl.com/wp-content/uploads/Appendix-A-AMPL-Book.pdf#page=7) in the [AMPL book](https://ampl.com/learn/ampl-book/).
