calling AIMMS com 4.0 vs 3.13 version

135 views
Skip to first unread message

laurent

unread,
Mar 5, 2018, 5:46:13 AM3/5/18
to ai...@googlegroups.com
Dear AIMMS community,

I am currently doing a conversion between AIMMS 3.13 and AIMMS 4.

I have a c# project that was originally working based on AIMMS 3.13 version and based on Aimms64.dll for calling AIMMS com.

I have now to make it work with AIMMS 4.0 but without breaking the compatibility with AIMMS 3.13. Meaning I need to have my C# application work whatever AIMMS version project is used.

To make it work with AIMMS 4.0 I have downloaded the AIMMS Launcher and I have added to the project reference the new Aimms.dll it contains.

It works fine when the Aimms project is an AImms 4 version, however it does not work well if the project is a AIMMS 3.13 project, Although the prj is opened and run, it seems that AIMMS com is opening it using AIMMS 4.8 version.


Based on this, I have two questions:
        - Is the Aimms.dll working with AImms 4.0 version suppose to work also for previous project (3.13) or should the AImms64.dll be used for "old" project ?
        - If the Aimms.dll can be used for both Aimms project version, how can I specify the version to use (AIMMS 4 vs AImms 3.13) when calling AIMMS com ? There is this AimmsSelector.dll but I havn't found that much resource onine as regard c# application.


I have found a python and c++ example here :


        Specifying this:     
                                 ISelectorPtr hSelector(CLSID_CSelector, NULL, CLSCTX_SERVER);
                                 IProjectPtr hProject = hSelector->GetAimmsProject(buffer);

        or this:
                                 import win32com.client  # import win32com

                                 projectName = "<path-to-project>\\RunAIMMS.aimms"
                                 AIMMS = win32com.client.Dispatch("AimmsSelector.Selector32") 
                                 project = AIMMS.GetAimmsProject(projectName)

but I am not sure about the C# equivalent and if using the AimmsSelector will solve my issue.


Thanks in advance for any help !

Regards

Laurent

laurent

unread,
Mar 8, 2018, 9:15:38 AM3/8/18
to AIMMS - The Modeling System
I was able to adjust my c# code and I am now doing the following hoping the the AimmsSelector will chose the right AIMMS version depending on the project I am trying to get, even if it is an "old".prj project which would need AIMMS 3.13 for instance (an not AIMMS 3.14) :


using Aimms4 = AimmsSelector;

Aimms4.ISelector selector = new Aimms4.CSelector();
Aimms4.IProject p = selector.GetAimmsProject(prj);

p.StartupMode = Aimms4.AIMMS_STARTUPMODE.STARTUP_HIDDEN;

Assert.AreEqual(p.ProjectOpen(prj, 1), 1, "Failed to open project");

and then If I want to get an Identifier valueI have the following get method:
        
static public String GetValue(Aimms4.IProject prj, String p)
        {
            Aimms4.IIdentifier identifier = prj.GetIdentifier(p);
            object ret = identifier.Value;
            return ret.ToString();
        }


However I have the following  COM error :

  ----> System.Runtime.InteropServices.COMException : Retrieving the COM class factory for component with CLSID {A0D7DDC0-1915-466C-A3C3-7087C0740532} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

at the line: Aimms4.ISelector selector = new Aimms4.CSelector();

I have added the AimmsSelector.dll into the reference of my c# project. Did I missed a step ?


Any Help ? 
Thanks


Laurent

laurent

unread,
Mar 8, 2018, 3:54:25 PM3/8/18
to AIMMS - The Modeling System
Hello, 

A little update as I was able to correct the class not registered error.
The code from the last message seems to work now however there is still one issue when the project that I am trying to open is a AIMMS 4 version project (with .Aimms extension) I get the following error:

  ----> System.Runtime.InteropServices.COMException : ProjectOpen failed.
Starting up the Aimms project failed --- Error opening project file: RSC.aimms
A project file must have extension ".prj"

I would like my code and AImmsCom to be able to open .prj as well as .aimms project with the right AImms version. Is it possible to do that ?

Thanks 

Laurent

Khang Bui

unread,
Mar 8, 2018, 8:07:35 PM3/8/18
to AIMMS - The Modeling System
Hello Laurent, 

You should be able to open both the .aimms and .prj type projects through the AIMMSCOM. 

Could it be the wrong arguments you are passing through? 

With this snippet of code I'm able to open both the .aimms and .prj projects so it should be possible.


            AimmsSelector.ISelector selector = new AimmsSelector.CSelector();

            AimmsSelector.IProject AimmsProject4 = selector.GetAimmsProject("C:\\Users\\Khang\\Documents\\AIMMS Issues\\Google Group\\Laurent\\Calling AIMMSCOM\\RunAIMMS.aimms");
            AimmsProject4.ProjectOpen("C:\\Users\\Khang\\Documents\\AIMMS Issues\\Google Group\\Laurent\\Calling AIMMSCOM\\RunAIMMS.aimms");

            AimmsSelector.IProject AimmsProject = selector.GetAimmsProject("C:\\Users\\Khang\\Desktop\\Calling AIMMSCOM\\RunAIMMS.prj");
            AimmsProject.ProjectOpen("C:\\Users\\Khang\\Desktop\\Calling AIMMSCOM\\RunAIMMS.prj");


Can you provide me with the code example you are using? 

Kind regards,

Khang Bui

laurent

unread,
Mar 9, 2018, 4:14:45 AM3/9/18
to AIMMS - The Modeling System
Hello Khang and thank you for your answer,

The Argument is correct because if I don't use the AimmsSelector,dll but the Aimms.dll directly it works  (without modifying the code) with the .Aimms extension ( but not anymore with the .prj extensions... project is opened but with a AIMMS 4 version)

PLease see below the full  part of the code that is suppose to open the AImms project: This a non regression tool which is supposed to open two project and compare the results.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Threading;
using System.Runtime.InteropServices;
using Aimms4 = AimmsSelector;

    public class Control
    {
        static Stack<Aimms4.IProject> licencesInUse = new Stack<Aimms4.IProject>();
        static Stack<Aimms4.IProject> licensesAvail = new Stack<Aimms4.IProject>();
        static Random rnd = new Random();
        const int nLicenses = 2;


        static public Aimms4.IProject Start(String prj, bool visible)
        {
            Aimms4.IProject ret = null;
            while (licensesAvail.Count + licencesInUse.Count < nLicenses)
            {
                System.Console.WriteLine("Adding a new AimmsCom object...");

                Aimms4.ISelector selector = new Aimms4.CSelector();
                Aimms4.IProject p = selector.GetAimmsProject(prj);
                //Aimms4.Project p = new Aimms4.Project();
                p.DefaultElementValuePassMode = Aimms4.ELEMENT_PASS_MODE.ELEMENT_BY_NAME;
                p.DefaultTuplePassMode = Aimms4.ELEMENT_PASS_MODE.ELEMENT_BY_NAME;
                if (visible)
                    p.StartupMode = Aimms4.AIMMS_STARTUPMODE.STARTUP_NORMAL;
                else
                    p.StartupMode = Aimms4.AIMMS_STARTUPMODE.STARTUP_HIDDEN;

                licensesAvail.Push(p);
            }

            while (ret == null)
            {
                Thread.Sleep(rnd.Next(1000));
                if (licensesAvail.Count > 0)
                {
                    licencesInUse.Push(ret = licensesAvail.Pop());
                }
                System.Console.WriteLine("Waiting for dispatch : " + prj);
            }

            System.Console.WriteLine(prj + " is getting a license token...");
            try
            {
                ret.ProjectClose();
            }
            catch (Exception exc)
            {
                System.Console.WriteLine("Catch exception during project close: " + exc.Message);
            }

            if (visible)
                Assert.AreEqual(ret.ProjectOpen(prj, 0), 1, "Failed to open project");
            else
                Assert.AreEqual(ret.ProjectOpen(prj, 1), 1, "Failed to open project");
            return ret;
        }


Thank you for your help

Regards

Laurent

laurent

unread,
Mar 9, 2018, 6:52:13 AM3/9/18
to AIMMS - The Modeling System
Hello Khang,

I was continuing some testing and actually i think that "project must have .prj extension" is not an error we should focus on.
If I set the path of my two project towards .aimms project and therefore using Aimms 4 or above version,  i have the following error:

System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.Runtime.InteropServices.COMException : Class not registered

at the line : Aimms4.IProject p = selector.GetAimmsProject(prj);

Do you have any idea what could cause this issue ? 
strangely the Aimms4.ISelector selector = new Aimms4.CSelector(); line before didn't cause any issue.

Thank you for your help

Laurent

Khang Bui

unread,
Mar 12, 2018, 8:14:45 PM3/12/18
to AIMMS - The Modeling System
Hi Laurent, 

Could you provide me with some more information about your AIMMS and computer's specifications?  What bit versions of AIMMS are you running and what are your computer's specifications(OS, bit version) along with the program you are using to compile the code?


-Khang

laurent

unread,
Mar 13, 2018, 8:03:48 AM3/13/18
to AIMMS - The Modeling System
Hello Khang,

I am on a windows 7 service pack 1 64 bit operating system.

I an trying to un AIMMS 3.13 64 bit version and Aimms 4.8 64 bit version as well:
- 4.8.3.322 x64
- Aimms-3.13.7.29-x64

The AImms Selector is : 1.0.0.54 64 bit as well.

I compile using visual studio 2010, in a x86 configuration using Net 4.0 framework.


I have tried to run my code using AIMMS 4.0 installation without using AImms selector and it works for .aimms projects, it seems that the issue is related to installation-free aimms version.
the Aimms Selector is registered in registry.
The error I get :
     System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
      ----> System.Runtime.InteropServices.COMException : Class not registered

does not mention any CLSID  and is not on the CSelector class call but on the GetAImmsProject Call.

I don't know what could cause the issue, thank you for your help

Regards

Laurent

Khang Bui

unread,
Mar 13, 2018, 7:38:19 PM3/13/18
to AIMMS - The Modeling System
Hi Laurent, 

Thanks for the information.  Although I'm on Windows 10, when attempting to build the code with the x86 configuration I get the same error, but not when I have it set to 'Any CPU' or 'x64' as the projects open fine then.  This was compiled in Visual Studio 2013 but I don't expect there to be much of a difference here.

For the references I'm using the Aimms 4.0 Object Library along with the AimmsSelector x64 2.0 Type Library.  

Does building in x64 with the mentioned references give you a different result?

Kind regards,
Khang

laurent

unread,
Mar 14, 2018, 7:36:50 AM3/14/18
to AIMMS - The Modeling System
Hello Khang.

When I use x64 Aimms Selector and compile in a 64 bit configuration I get the following error on line  Aimms4.IProject p = selector.GetAimmsProject(prj); :
-      System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.

      ----> System.Runtime.InteropServices.COMException : Class not registered



When I use x86 Aimms Selector and compile using a 32 bits congiruation I got an error as well but on line  Aimms4.ISelector selector = new Aimms4.CSelector();

  ----> System.Runtime.InteropServices.COMException : Retrieving the COM class factory for component with CLSID {A0D7DDC0-1915-466C-A3C3-7087C0740532} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

What do you mean by :


For the references I'm using the Aimms 4.0 Object Library along with the AimmsSelector x64 2.0 Type Library. 

I get only to choose the Aimms selector dll in : C:\Users\...\AppData\Local\AIMMS\IFA\AIMMSLauncher\1.0.0.54 either x86 or x64.
I don't add in the references any specific AImms Object Library, I assumed the Aimms selector is chosing the right one depending on the project version.
I have tried once to use directly the Aimms 4.0 Object library (x64) and compile on a x86 configuration and it was working fine but only for the .aimms project not for the AIMMS 3 projects.

Regards

Laurent

:

Khang Bui

unread,
Mar 14, 2018, 7:06:26 PM3/14/18
to AIMMS - The Modeling System
Hi Laurent, 

Are you able to add the references I mentioned through the Visual Studio Reference Manager?  This is what mine looks like:


I believe you should be fine with just the AimmsSelector x64 2.0 Type Library selected.  Do you see this option and are you able to apply the setting and test? 


The other way by browsing directly for the .dll also works for me with just the AimmsSelector.dll added in my reference manager. 


All running fine with this code that opens up the .aimms and .prj project in Aimms 4.8 x64 and Aimms 3.13 x64


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using AimmsSelector;


namespace RunAIMMS

{

    class Program

    {

        static void Main(string[] args)

        {

            AimmsSelector.ISelector newselector = new AimmsSelector.CSelector();

            AimmsSelector.IProject Aimms4Project = newselector.GetAimmsProject("C:\\Users\\Khang\\Documents\\AIMMS Issues\\Google Group\\Laurent\\Calling AIMMSCOM\\RunAIMMS.aimms");

            Aimms4Project.ProjectOpen("C:\\Users\\Khang\\Documents\\AIMMS Issues\\Google Group\\Laurent\\Calling AIMMSCOM\\RunAIMMS.aimms");


            AimmsSelector.ISelector selector = new AimmsSelector.CSelector();

            AimmsSelector.IProject AimmsProject = selector.GetAimmsProject("C:\\Users\\Khang\\Desktop\\Calling AIMMSCOM\\RunAIMMS.prj");

laurent

unread,
Mar 20, 2018, 6:57:42 AM3/20/18
to AIMMS - The Modeling System
Thank you Khang for these details,

There are actually two seperate problem I have indentified:
- First as my application run two aimms version using aimmscom and compare the results, it open Aimms com for the first aimms version that is executed and keep the saime AIMMSCOM interface for the second version. Therefore if it starts with the .prj file then when it executes the second project based on the .aimms file it fails as it expects a .prj file.
- second issue is with the AIMMSCOM from AIMMS 4.8 version, I have replaced it by the one from AIMMS 4.0 installation and now if the first project that is executed is a .aimms, it works fine, however AIMMS 4.0 is launched instead of AIMMS 4.8.

I don't know why the AIMMSCOM.exe from the AIMMS 4.8 installation does not work properly, I tried to de-install it and re install it with no success.

Sincerely

Laurent

laurent

unread,
Mar 20, 2018, 10:00:17 AM3/20/18
to AIMMS - The Modeling System
Hello Khang,

I was looking to my registry to to find the AIMMS 4.8 COM object but I was not able to find him.
I  have found the one of AIMMS 4.0 : please see the print screen in the word document attached.

However I can't find the one for AIMMS 4.8, it seems that the COM object get registered only for AIMMS version that are not "installation free".

PLease could you tell me the manual procedure to do it ?

Sincerely

Laurent
AIMMSCOM_Registration.docx
Reply all
Reply to author
Forward
0 new messages