Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  cocncrete for C++

    Posted 07/06/12 11:48 AM

    Originally posted by: Sara94


    Hi
    I am new in using concrete technology.I wrote a small program, this code works well if I use scanf, but if I read data from a file it does not work, I think its error is related to fscanf.
    #include<stdio.h>
    #include<math.h>
    #include <stdlib.h>
    #include<conio.h>
    #include <ilcplex/ilocplex.h>

    int e5,d,extra;
    FILE* in;
    ILOSTLBEGIN

    int ple(int extra93){
    IloEnv env;

    IloModel model(env);

    IloNumVar a( env, 3, 100, ILOINT);
    IloNumVar b( env, 2, 100, ILOINT);
    model.add(IloMinimize(env, 1*a+d*b));
    model.add(a+b==6);

    IloCplex cplex(model);
    cplex.solve();

    env.out() << "Cost:" << cplex.getObjValue() << endl;

    env.end();

    e5=0;
    return(e5);
    }
    int main ()
    {
    in = fopen("in.txt", "r");
    fscanf(in,"%d",&d);
    extra=0;
    ple(extra);

    }
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: cocncrete for C++

    Posted 07/06/12 06:15 PM

    Originally posted by: SystemAdmin


    How does your file in.txt look like?
    If you print out the value of 'd' after you read it, does it look as expected?
    I also see that you are mixing C code (fopen, fscanf) into your C++ program. You may want to use C++ classes to do the same:
    // Read integer from console:
    #include <iostream>
    int d;
    std::cin >> d;
    // Read integer from file:
    #include <fstream>
    int d;
    std::ifstream in("in.txt");
    in >> d;
    in.close();
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: cocncrete for C++

    Posted 07/07/12 01:50 AM

    Originally posted by: Sara94


    Thanks for your help
    my problem was solved, but I have a new problem. when i run the program, i face this error:

    IBM ILOG CPLEX Optimization Studio TeamEAT Edition
    This application has requested the runtime to terminate it in an unusual way.please contact the application's support team for more information.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: cocncrete for C++

    Posted 07/07/12 05:53 AM

    Originally posted by: SystemAdmin


    I guess you are getting some sort of exception? You should catch that exception and print the error message, that will allow a better analysis of your problem.
    To catch the exception and print its message rewrite your main() program to something like this:
    int main(void)
    {
       try {
          // your code here
          ...
          return 0;
       } catch (IloException& e) {
          std::cerr << "IloException: " << e << std::endl;
          return -1;
       } catch (...) {
          std::cerr << "Unknown exception!" << std::endl;
          return -1;
       }
    }
    

    Do you see any useful messages when you do that?

    Maybe also have a look at the examples that come with CPLEX and illustrate how to write code that uses Concert C++.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: cocncrete for C++

    Posted 07/07/12 07:13 AM

    Originally posted by: Sara94


    I wrote this code and the result is:

    Concert exception caught: CPLEX Error 1217: No solution exists.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: cocncrete for C++

    Posted 07/07/12 08:05 AM

    Originally posted by: SystemAdmin


    OK, then it is pretty clear what you are doing wrong: Your model has no solution but you are still trying to do
    env.out() << "Cost:" << cplex.getObjValue() << endl;
    

    This attempts to access the current solution but as there is no solution it throws an exception.
    Note that function cplex.solve() returns true if a solution is available. So your code should look like this:
    if ( cplex.solve() ) {
       // CPLEX found at least one feasible solution.
       // We can query that solution.
       env.out() << "Cost:" << cplex.getObjValue() << endl;
    }
    else {
       // No solution was found. The model is infeasible or
       // some sort of limit (time limit, node limit, ...)
       // expired before a feasible solution could be found.
       env.out() << "No feasible solution found." << endl;
    }
    

    Again, it might be helpful to go through the examples that come with CPLEX to learn about the different results with which a solve() may return and how to handle them.
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: cocncrete for C++

    Posted 07/08/12 07:12 AM

    Originally posted by: Sara94


    Thanks a lot for your help. my problems were solved.
    #CPLEXOptimizers
    #DecisionOptimization