Solved

Save Project from a procedure


Hi all, is there a way to save your project from a procedure (as can be done with cases: https://how-to.aimms.com/Articles/258/258-save-a-case-from-aimms-procedure.html)? If not, is it possible to let AIMMS automatically save the project each time a procedure is run?

 

 

icon

Best answer by luispinto 10 January 2023, 15:42

View original

10 replies

Userlevel 4
Badge +5

Dear @oomse 

I noticed the issue and have corrected the article you quoted. It was still using an old case management style in AIMMS.

Please use the following procedure to save your case. You can also go back to the article which has been updated.

Procedure SaveCase {
Arguments: (sp_CaseName);
Body: {
! Save the case in the folder "data".
if not DirectoryExists( "data" ) then
DirectoryCreate("data");
endif ;
CaseFileSave( "data\\" + sp_CaseName, AllIdentifiers );
}
StringParameter sp_CaseName {
Property: Input;
}
}

Thank you!

Hi luispinto,

Thank you for your quick response and answer. However, I was actually looking for a way to save the entire project using a procedure. So, to save adjustments to the code without clicking on ‘File’ and ‘Save Project’ or using Ctrl+S, but use a line of code in a procedure instead. I saw that it was possible for saving cases, but I thought that was only for saving data that is produced with the project. Therefore, I was wondering if the entire project (the code) can also be saved with a procedure.

Userlevel 5
Badge +7

What is the problem you are trying to solve with this? Normally, your model will not be changed via code, but only changes you make in the model tree (with the exception of runtime libraries with MEF, but those are not saved anyway when you save the project).

We would like to save the code of the model that is used to create the results with. With this, we want to be able to archive and reproduce our results. However, as our work requires us to make many adaptations to the code very often, it is desirable to let it save the project automatically after every run. We know that you can also do it manually by using Ctrl+S or using the ‘File’ and ‘Save Project’, but unfortunately it sometimes happens that we forget to save it. AIMMS of course asks you to save the project when you close it, but we sometimes need to change the code in between two or more runs. So, for the first runs we do not get a reminder to save the project.

 

We already wrote a procedure in AIMMS that automatically archives all the data and tools that are used after every run. That is working very well, but the only issue that is left now, is that it archives the project of the version before it was opened/saved. And when you accidentally forget to save it before the run, you save the wrong version of the project.

 

So, to be absolutely certain that we have the correct code with the corresponding data output, we are searching for an option to save the code automatically after every run. This would make it easier to archive and reproduce our results.

Userlevel 5
Badge +7

Not sure if something like this would be possible natively with AIMMS. Can only think of very hacky solutions that might not be very robust

Userlevel 4
Badge +5

The ways I think of it are UI related, that is, after optimization is completed inform the user they must save the project before moving on. It does not guarantee they will, but it helps.

And if you think this function would be very useful, please feel free to add it to our ideation section!

https://community.aimms.com/ideas

Thank you both for your reactions and effort. As a workaround, I think that I will indeed create a message that tells us to save the project. Thank you for the tip! Unfortunately, I do not have access to the ideas page (while logged in).

 

 

Userlevel 6
Badge +6

Hi @oomse - you should have access to the Ideas section now!

Userlevel 4
Badge +5

@oomse, I'm wondering whether those continuous model changes are mostly wrt data that you store as part of the model, or whether you actually change the model formulation that often (which I find much harder to imagine).

In the first case, I would argue that in most cases non-static data should not be part of the model, but should be stored separately (file, database, CDM). This would give you a way to store model state without having to save the model on every run.

In the second case, if you have to change the model formulation that often, isn't it possible, and much more natural, to make the model formulation more data driven? In that case, changes in model behavior are driven by changes in data (potentially by following different branches in your code through if-then-else constructs if need be). Also, you can have a superset of variables and constraints, only a subset of which you can actually include in your optimization model. This allows for another method to make an optimization model with e.g. different objectives in a data driven manner. By making your model formulation data driven, you end up in the first case again. 

Lastly, it seems your current approach is to set apart a version of the model with every case that you run. I would argue that the use of a version control system like git would be a much better approach. Not only will it save a tremendous amount of space (as you only have to add a reference to the model revision that you were using to run the case, which can be easily recreated on disk if need be), but using version control also gives you a very convenient way to later inspect what actually changed in between revisions. Using CDM for storing your data, will also give you version control on your data, allowing you to create a new scenario, based on some previous revision of your data.

@MarcelRoelofs

Unfortunately, the continuous model changes are with respect to the model formulation.

Changes to the data happen even more often at a much bigger scale and we are indeed dealing with those changes through the use of databases.

We tried to set up the model formulation as general as possible and indeed also try to make the model formulation as much data driven as possible (e.g. setting up different scenario's). But unfortunately we can't capture everything with this. We work in a very vivid work environment which means we need to add additional features to the model very often. I think that our work is a little different than the work of most other users of AIMMS, which creates this situation.

We already use git for version control on the model to keep track of the changes. I have not checked the possibilities to use git for archiving runs, it may indeed be helpful and I will look further into that. Thank you!

 

 

Reply


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator