AMPL could not be started

When I download C++api to execute the official case in Linux environment, there is an error message as shown in the picture, which of you have encountered similar error message?

1 Like

Hi @Yuanmin,

Is that directory where you have AMPL installed? To ensure that the right AMPL executable is found, you can add the AMPL installation directory to the first position of the environment variable PATH, or set an environment as follows:

ampl::Environment env("full path to the AMPL installation directory");
ampl::AMPL ampl(env);

Thank you for your reply, I have set it up that way, but it still reports an error, is there a reference format for the installation path?

Hi @Yuanmin,

The format of the installation path is typically as follows for Linux:

ampl::Environment env("/home/username/ampl.linux-intel64/");
ampl::AMPL ampl(env);

Already done so, is there a step I’m missing?

Hi @Yuanmin,

Could you please send us the output of ls -l /complete/path/to/ampl.linux-intel64? It may be some issue with file permissions.

Hi @Yuanmin,

That is only the AMPL API module. You also need to have AMPL and solvers installed. For that you can download (contains AMPL and all solvers). In ampl::Environment you need to point to the location where AMPL is installed, not the location where the API is installed.

Thank you very much for your help in answering my questions!

I have set an iterative initial value for the variables in the model, and I have placed them in a text file. How can I set them? In addition, the same model is much faster to call in matlab than when I use the C++api. I would like to ask how I can optimize settings to make my C++calls faster?

Hi @Yuanmin,

What is the format you used for the initial values? If you use the AMPL data format you can use ampl.readData("filename.dat");.

Regarding the performance different between MATLAB and C++, C++ should be faster in general as the MATLAB API is implemented on top of it. Could you provide two small examples (one in Matlab and another in C++) where C++ is slower? Depending on the way you pass the data, there are some methods that are faster than others.

BTW, they way are setting ipopt_options, only the last value is kept. If you want both options you need to use ampl.setOption("ipopt_options", "max_iter=100 print_level=0").

When I was learning about other people’s open source code on github, the content of that file is this:“ fix x:=100;…”is something like an initial value assigned to the variable x that makes the algorithm converge faster. In matlab they call it in .run file ,like this, “include filename”.But I don’t know how to achieve the same effect using C++api.

Using the C++ API you can call"");.

I have a variable of this type and I want to convert it to a normal array for my subsequent graphing.What should I do?
2023-06-05 14-34-40 的屏幕截图

Hi @Yuanmin,

You can iterate through an ampl::DataFrame as follows:

ampl::AMPL ampl;
ampl.eval("var x{1..10,1..10};");
auto df = ampl.getVariable("x").getValues();
for (auto row : df) {
  std::cout << "x[" << row[0].dbl() << "," << row[1].dbl() << "] = " << row[2].dbl() << std::endl;