0
votes

I am making a simple console application in Qt (Qt Creator 3.3.2 (opensource) Based on Qt 5.4.1 (MSVC 2010, 32 bit)), which uses cplex (12.3.0.0). Code looks like:

SimpelConsole.pro

QT       += core    
QT       -= gui

TARGET = SimpelConsole
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app    
SOURCES += main.cpp

INCLUDEPATH += C:\ILOG\CPLEX123\cplex\include
INCLUDEPATH += C:\ILOG\CPLEX123\concert\include
INCLUDEPATH += C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include
DEFINES += IL_STD

#// cplex123.lib library
win32: LIBS += -L$$PWD/../../../../../ILOG/CPLEX123/cplex/lib/x64_windows_vs2010/stat_mda/ -lcplex123    
INCLUDEPATH += $$PWD/../../../../../ILOG/CPLEX123/cplex/lib/x64_windows_vs2010/stat_mda
DEPENDPATH += $$PWD/../../../../../ILOG/CPLEX123/cplex/lib/x64_windows_vs2010/stat_mda

#// ilocplex library
win32: LIBS += -L$$PWD/../../../../../ILOG/CPLEX123/cplex/lib/x64_windows_vs2010/stat_mda/ -lilocplex    
INCLUDEPATH += $$PWD/../../../../../ILOG/CPLEX123/cplex/lib/x64_windows_vs2010/stat_mda
DEPENDPATH += $$PWD/../../../../../ILOG/CPLEX123/cplex/lib/x64_windows_vs2010/stat_mda

#// concert.lib library
win32: LIBS += -L$$PWD/../../../../../ILOG/CPLEX123/concert/lib/x64_windows_vs2010/stat_mda/ -lconcert    
INCLUDEPATH += $$PWD/../../../../../ILOG/CPLEX123/concert/lib/x64_windows_vs2010/stat_mda
DEPENDPATH += $$PWD/../../../../../ILOG/CPLEX123/concert/lib/x64_windows_vs2010/stat_mda

main.cpp

#include <QCoreApplication>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ilcplex/ilocplex.h>
#include <ilcplex/cplex.h>

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);

    double elapsed_time; clock_t start_time;
    start_time= clock();
    int i, j;    
    int nbCities = 5;
    int nbOvens = 2;

    double d[2][5];
    d[0][0]= 130; d[0][1]= 70; d[0][2]= 50;  d[0][3]= 100; d[0][4]= 150;
    d[1][0]= 90;  d[1][1]= 70; d[1][2]= 250; d[1][3]= 130; d[1][4]= 200;
    double a[5];
    a[0]=240000;  a[1]=240000; a[2]=240000;  a[3]=240000;  a[4]=240000;
    double c[2];
    c[0]=500000; c[1]=15000000;
    double f[2];
    f[0] = 80; f[1] = 100;
    int cost = 1; // transport cost

    IloEnv env; // create the environment
    try{
        IloModel model(env);                       // create a model
        IloNumVarArray variables(env);             // create variable set
        IloRangeArray constraints(env);            // create constraint set
        IloObjective objective = IloMinimize(env); // create objective function

        // Build variables
        char jchar[3], name[15];
        for (j=0; j!=nbCities*nbOvens; j++){
            strcpy(name, "x_");
            itoa(j, jchar, 10);
            strcat(name, jchar);
            IloNumVar xVar(env, 0, 1, ILOINT, name);
            variables.add(xVar);
        }

        // Build constraints
        for (i=0; i!=nbOvens; i++){
            strcpy(name, "cap_restr_");
            itoa(i, jchar, 10);
            strcat(name, jchar);
            constraints.add(IloRange(env, -IloInfinity, c[i], name));
        }
        for (i=0; i!=nbCities; i++){
            strcpy(name, "flow_restr_");
            itoa(i, jchar, 10);
            strcat(name, jchar);
            constraints.add(IloRange(env, 1, 1, name));
        }

        // Set constraints coefficients
        for (i=0; i!=nbOvens; i++){
            for (j= 0; j!= nbCities; j++){
                constraints[i].setLinearCoef(variables[j+i*nbCities], a[j]);  // cannot exceed capacity - constraint
            }
        }
        for (i=0; i!=nbCities; i++){
            for (j=0; j!=nbOvens; j++){                    constraints[nbOvens+i].setLinearCoef(variables[i+j*nbCities], 1);        // flow constraint
            }
        }

        // Build objective function
        for (i=0; i!=nbOvens; i++){
            for (j=0; j!=nbCities; j++){
                objective.setLinearCoef(variables[i*nbCities+j], cost*a[j]*d[i][j]+f[i]*a[j]);
            }
        }

        model.add(objective);
        model.add(constraints); // variables are included implicitly
        IloCplex cplex(model);
        cplex.exportModel("model.lp"); // write the model to a file
        cplex.solve();

        double intTolerance = cplex.getParam(IloCplex::EpInt);

        IloNumArray values(env);
        double obj = cplex.getObjValue();
        printf("Objective value: %3.2f\n",obj);
        cplex.getValues(values, variables);
        int total = 0;
        for (j=0; j!=nbOvens*nbCities; j++){
            if (values[j] > intTolerance){
                printf("Object %d \n", j);
            }
        }

    }catch(IloException &e){
        std::cerr << "Concert exception caught: " << e << std::endl;
    }
    env.end(); // destroy the environment (to free memory)

    printf("Press Enter to continue...\n");
    getchar();

    return app.exec();
}

This is a simple allocation model. When building, I get 32 errors like:

main.obj:-1: error: LNK2019: unresolved external symbol "public: double __thiscall IloAlgorithm::getObjValue(void)const " (?getObjValue@IloAlgorithm@@QBENXZ) referenced in function _main

I already cleaned, closed, restarted, ran qmake again, and rebuilt... but still the same errors...

1

1 Answers

0
votes

Lookslike your project not referencing the library having IloAlgorithm class. Kindly check your lib and calling conversion. Libraries may be compiled in cdecl or stdcall.

Refer this link also https://msdn.microsoft.com/en-us/library/799kze2z.aspx