Jun 13, 2011

Configure Visual studio C++ 2008 express edition with IBM Ilog Cplex and Concert libraries

I posted a couple of days ago , a Makefile for C++ project using IBM-ILOG cplex solver and the Concert library. So I thought I should do the same thing for the windows guy. First you ll need a Visual studio, i recommend VS 2008 C++ express edition, why speeding your money on a non worthy C++ editor, ( I ll try to configure netbeans on windows to bypass the VS )
First you need to create an empty C++ application

1 - Then you go to your project Menu and choose properties.




2 - In the configuration manager, change the configuration from debug mode to Release ( If you are going to use concert ; you have to program without debugging as it uses macros incompatible with the debug flags that the compilor add to your code), that the price that you have to pay with concert it's a double eddged sword. You write less code, but if you have an error you have to start guessing and trust me you could loose a lot of your time guessing and trying to figure out what went wrong.





3- You need to change compiler flags ( aka C/C++ in the configuration settings)

In order to use any C++ library you need the library itself .lib and the Header files (*.h or *.hpp). The lib 's header files indicate the compiler to the content of the lib file( a sort of Table of content). So when you compile your code, the compiler only check if the function you are calling figures in the header files and that you are using the proper argument to make the call. After the compilation of your cpp files into object files , the assembler / linker will link your compiled code (*.o) with acttuel function in the lib and produce the executable.

In our case we need to tell the compiler the path to the header files for cplex and concert libs .So you will need to add the path in the Additional Include Directories. you can use the small button on the path line to choose via explorer the directories. ( there is two include folders that you need: the cplex include folder and another include folder in the concert folder )




4-Disable the debug information format ( It could be that it's not required any more)




5 -Add IL_STD to the preprocessor definition ; it's the equivilant of -D in gcc , you can a define IL_STD at begining of your main file; i didn't check the files in the cplex include directory to see exactly what is the effect of this option . And also It could be that its not used any more




6-I don't remmeber why, but I usually choose MT as a Runtime library and in the next section I choose the library in the in stat mta ( I could be wrong , may be you can check if there is any impact on the speed of the execution )




7 - After the compilation you need to assamble your code. The linker wil assemble all the .o files into an executable and will need the libraries that you are calling to make the final excutable. You need to add to the Additional Dependencies in Input section of the linker , the exact location of you cplex library and concert + winsoc32 lib

In my case I had to add the following line :
wsock32.lib
C:\ILOG\CPLEX_Studio_AcademicResearch122\cplex\lib\x86_windows_vs2008\stat_mta\cplex122.lib
C:\ILOG\CPLEX_Studio_AcademicResearch122\cplex\lib\x86_windows_vs2008\stat_mta\ilocplex.lib
C:\ILOG\CPLEX_Studio_AcademicResearch122\concert\lib\x86_windows_vs2008\stat_mta\concert.lib



Tip Use ( use the windows explorer aka my computer ) , browse to the folder in question then right click on folder hiearchy satuts bar and copy the path


Jun 12, 2011

Use the send mail to send the results from the server

I was trying to find a way to send the results of the calculation done on a server to my email
I found this code this code on this post from ambikeh: http://www.unix.com/302072420-post2.html for more info on the send command http://linux.about.com/od/commands/l/blcmdl8_sendmai.htm

But i need to say that i didn t have time to test it

( cat << ! FROM : $FROM To : $TO Subject : ${SUB} Cc : ${CC} ! cat << ! HOPE THIS WORKS Test123 This sample E-mail message with the Unix sendmail utility. ! #uuencode ${1} ${1} ! ) | /usr/lib/sendmail -vt

Jun 11, 2011

bash script to check if a file or a folder exist

This is a cool , I always wanted to know how to check if a file exist or not ( could submited by monk on this link http://nixcraft.com/shell-scripting/93-script-how-check-if-file-exists.html )

files="/dev/MAKEDEV /etc/makedev.d /usr/sbin/mksock"
# $i will hold single file at a time in following loop
for i in $files
do
if [ ! -f $i -o ! -d $i ]; then
exit 1
fi
done


As I was writing shell code I ll add also some links to a bash scripting manual and another for reguraler exprssions , I have a think head but i have a tendency to complety forget who the regex work , you have to admit that cobol people gave us the worst heritage ever
For the shell scripting you can you can start from here : http://www.freeos.com/guides/lsst/
For the reg ex ( mainly sed and grep ) check this link : http://www.bsd.org/regexintro.html, for sed http://www.grymoire.com/Unix/Sed.html

Map and synchronize a local directory and distant shared directory

Map a drive

To Map a distant shared folder or even a local one using Dos command prompt

Open a command prompt and lauch this command

For a local directory



subst Q: "C:\Documents and Settings\hb\"



For a shared directory on a different machine



subst z: "\\Shared Server\hb\My Documents"


Synchronize two folder

To do sync to folder , we will you a great command, that microsoft incorporated as an external command and it's the "xcopy" , I am pretty sure that microsoft bought the company that developped this tool ; as they did with the excel .
For more info on xcopy or the list of external command visit this site that i recommand to visit from time to time http://www.computerhope.com

now back to how to sync the folder ; you create a batch file let's call it sync.bat
and add those two line and xcopy will do every thing for you


xcopy "c:\localfolder" "q:\remotefolder" /S /Y /D
xcopy "q:\remotefolder""c:\localfolder" /S /Y /D



Run the batch file and tadah its a miracle ; the data of the two folder will be merged and they and folder will become an image for one another.

Scheduele automatic sync

Instead of manually running the sync.bat , we can ask the scheduler to execute it every day by using the at command for more information on the at command and some tweaks check this site : http://ss64.com/nt/at.html


at 00:10 /every:M,T,S sync.bat


but due to some user previleges problem as the local system runinng the scheduele don't have the rights to access a remote directory
use the graphical interface to add a task on the win scheduler

Jun 10, 2011

A clean MakeFile for a C++ project using ILOG Cplex + Concert Library

Most of people that want to create IBM - ILOG Cplex project using C++ on linux, they take a file in the example directory of Cplex and copy paste it in the same example directory and then add a new entry in the Makefile as they are adding a new example.


But if you what to create a clean project an a separate directory you have to create your own Make File here is an example Make file that I did , it will automatically scan the (Source file directory )

Here is the architecture of the normal C++ in my sense ( it would be better to have header files in a separate directory, but I started the project using Visual studio on windows)


Project Directory
|__ MakeFile
|__Exe
|__src (dir)
| |__cpp(dir)
| |__ CPP Files + H Files
|__obj(dir)
|__data(dir)
|__ *.dat ; *.xml ;*.mps Files ( The instances of the problem that you want to test)



Of course you can add separate include directory but I put my Header files with the sources (sorry again for that it’s partially the VS fault ) but in the Makefile its already build to have a separate header Files .


You need to change the EXDIR and point it to where you want build the executables and run them.

If you are using 64 bit machine or itanium you can change the SYSTEM for x86_sles10_4.1, you can find this value in the make file in the cplex example direcory.

And also you need to change the ILOGSTUDIODIR to where you have installed ILOG.

NB: Dont forget to change the envirnment variable and add the path for the ILM.

You should update your ./bash_rc file and and something similare to : (watch out for the architecture 32 or 64 and change the library path accordinly
export ILOG_HOME=/home/balbaki/ILOG/CPLEX_Studio_AcademicResearch122

export LD_LIBRARY_PATH=$ILOG_HOME/cplex/bin/x86-64_sles10_4.1/:$LD_LIBRARY_PATH

export ILOG_LICENSE_FILE=/home/balbaki/ILOG/ILM/access.ilm


This make file was build for the IBM -ILOG Cplex v 12.2 but i think it should work on the previous versions as well

#===========================MakeFile==============================
# For Cplex + Concert Projects
# by Hassan Baalbaki www.hassanbaalbaki.com
#================================================================


SYSTEM = x86_sles10_4.1
LIBFORMAT = static_pic

EXDIR = /home/hb/dev/GlobalPlanner/MIP

#------------------------------------------------------------
#
# When you adapt this makefile to compile your CPLEX programs
# please copy this makefile and set CPLEXDIR and CONCERTDIR to
# the directories where CPLEX and CONCERT are installed.
#
#------------------------------------------------------------
ILOGSTUDIODIR =/home/hb/ILOG/CPLEX_Studio_AcademicResearch122
CPLEXDIR = $(ILOGSTUDIODIR)/cplex
CONCERTDIR = $(ILOGSTUDIODIR)/concert




# ---------------------------------------------------------------------
# Compiler selection
# ---------------------------------------------------------------------

CCC = g++
CC = gcc
JAVAC = javac

# ---------------------------------------------------------------------
# Compiler options
# ---------------------------------------------------------------------

CCOPT = -m32 -O -fPIC -fexceptions -DNDEBUG -DIL_STD


# ---------------------------------------------------------------------
# Link options and libraries
# ---------------------------------------------------------------------

CPLEXBINDIR = $(CPLEXDIR)/bin/$(BINDIST)
CPLEXLIBDIR = $(CPLEXDIR)/lib/$(SYSTEM)/$(LIBFORMAT)
CONCERTLIBDIR = $(CONCERTDIR)/lib/$(SYSTEM)/$(LIBFORMAT)

CCLNFLAGS = -L$(CPLEXLIBDIR) -lilocplex -lcplex -L$(CONCERTLIBDIR) -lconcert -m32 -lm -pthread



all:${DIRS}
make all_cpp

execute: all
make execute_cpp


CONCERTINCDIR = $(CONCERTDIR)/include
CPLEXINCDIR = $(CPLEXDIR)/include

#EXINC = $(EXDIR)/include
EXINC = $(EXDIR)/src/cpp
EXDATA = $(EXDIR)/data
EXSRCCPP = $(EXDIR)/src/cpp


CFLAGS = $(COPT) -I$(CPLEXINCDIR)
CCFLAGS = $(CCOPT) -I$(CPLEXINCDIR) -I$(CONCERTINCDIR)


#------------------------------------------------------------
#
#Build and Execute directory
#
#------------------------------------------------------------



INC_PATH = $(EXSRCCPP)
SRC_PATH = $(EXSRCCPP)
OBJ_PATH = ${EXDIR}/obj



SOURCES = ${wildcard ${SRC_PATH}/*.cpp}
OBJECTS = ${patsubst ${SRC_PATH}/%.cpp, ${OBJ_PATH}/%.o, ${SOURCES}}


INCLUDES = -I${INC_PATH}

DIRS = ${OBJ_PATH}


#------------------------------------------------------------
# make all : to compile all.
# make execute : to compile and execute some instances
#------------------------------------------------------------



CPP_EX = globalplanner




all_cpp: $(CPP_EX)


execute_cpp: $(CPP_EX)
./globalplanner $(EXDATA)/small.dat 3




# ------------------------------------------------------------

clean :
/bin/rm -rf *.o *~ $(OBJ_PATH)/*.o
/bin/rm -rf ${SRC_PATH}/*~
/bin/rm -rf $(CPP_EX)
/bin/rm -rf *.mps *.ord *.sos *.lp *.sav *.net *.msg *.log *.clp

# ------------------------------------------------------------
#
# The Cpp and *.o Files
#


all: ${DIRS} globalplanner

${OBJ_PATH}:
mkdir -p $@


${OBJ_PATH}/%.o : ${SRC_PATH}/%.cpp
$(CCC) ${INCLUDES} -c $(CCFLAGS) $< -o $@

globalplanner: ${OBJECTS}
$(CCC) $(CCFLAGS) $^ -o globalplanner $(CCLNFLAGS)


# Local Variables:
# mode: makefile
# End:


#======================== END OF MakeFile =========================

The easiest way to run an executable that take as entry files that are on another directory



This tutorial is for shell - unfamiliar people; it unable them to run; on the command prompt a program that take as an input a file that is on different directory. (If you know how to use cd .. ) this tutorial isn't for you. But it could accelerate the process if you don't want to type a long command each type if you have multiple sub directory between the executable and data file.




Let’s say we have this architecture for a program called hello and it takes as input the data1.dat that is in a sub directory



C:\>
|__hello (dir)
|__hello.exe
|__data(dir)
|__data1.dat

First you create in you data folder a shortcut to the executable:
1- Go to data Folder and right click
2- Choose to new -> Shortcut

3- Browse to the location of your executable (hello world)


4- Finish the process
5- Right click on the newly create link and go to properties
6- Empty the field Run In. (it is c:\hello\) delete it.

Create a cmd shortcut
One last thing create also cmd shortcut in the data directory if you don't want to type cd each time

1- Go to data Folder and right click
2- Choose to new -> Shortcut


3- Type cmd in the path and then click on next then finish




4- Also you should Right click the link and empy the field Run




To run the program :

Click on the (cmd) link that you created and the command prompt should pop up , Type the name of the link to you executable then the name of your data input file .
In this case it should be
C:\hello\data> hello.exe.lnk data1.dat
NB : I know that in this case we can also time ..\hello.exe data1.dat but this example was written to help the people that are unfamiliar with shell and the data is in sub -sub-sub directory

May 25, 2011

How to install Netbeans IDE , with c++ compilors for the SOC-RAD project

Installation On windows

Before installing the IDE - ( Net beans ) , and the project itself , you should

  1. Install a c++ compiler and debugger and make
  2. Check if java JRE is installed on your machine and installed it otherwise.
  3. Install Netbeans from www.netbeans.org

Or 2’- Install the bundle netbeans + jdk from oracle site : http://www.oracle.com/technetwork/java/javase/downloads/jdk-netbeans-jsp-142931.html

4-Download the source files and create a project.


Part I : Install the gcc and gdb and make:

First I recommend MinGW instead of Cgwin .

**To check if it’s installed

  1. type cmd in the Run command
  2. In the Command prompt opened type the following command “g++- v “ if you don’t get an error that means it’s installed you don’t need to install the c++ compiler
  3. In the Command prompt opened type the following command “make –v” if you don’t get an error that means it’s installed you don’t need to install the MSYS.

If you want to install it the hard way / manually follow this link : http://www.mingw.org/wiki/InstallationHOWTOforMinGW

If not do the simple way and use the installer :

http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get-inst/

1. Download the latest version

2. Choose the default settings till you arrive the check list

3. You should check from the chck list C++ compiler ( g++ ) and ) and the developer kit that includes MSYS ( make)

4. Update : the Path

4.1. Right-click on "My Computer" and select "Properties".

4.2. Click Advanced -> Environment Variables. (AvancĂ© -> variables d’environnement)

4.3. In the box entitled "System Variables" scroll down to the line that says "PATH" and double-click the entry.

4.4. You will be presented with a dialog box with two text boxes, the bottom text box allows you to edit the PATH variable. It is very important that you do not delete the existing values in the PATH string, this will cause all sorts of problems for you!

4.5. Scroll to the end of the string and at the end add ;C:\MinGW\bin;C:\MinGW\MSYS\1.0\bin; (if you kept to the recommended default installation directory). Don't forget the semicolon; this separates the entries in the PATH.

4.6. press OK -> OK -> OK and you are done.

5. After the installation open and new cmd and check if g++ and make are installed ( see above the ** section)

Part 2 : JDK / JRE (Check the option part 2’)

First JRE , stands for java run time environment , and if you are using the new terminology of oraclem it’s called “ java 6 “

To check if it’s installed

  1. type cmd in the Run command
  2. In the Command prompt opened type java- version

You should get the version of your java runtime,

if not go to ( http://www.java.com/en/download/help/index.xml or http://www.java.com/en/download/manual.jsp#win :) and install it ( I recommend also to install the JDK / SDK ( stands for java development kit : ) , if you are planning to develop java programs , you ll only loose some disk storage space.-

Part 3: Install Netbeans

Download the netbeans from the following link

http://netbeans.org/downloads/index.html

Of course choose either the full version or the C++ version.

Part 2’ : Install the the bundles JDK+netbeans :

Oracle now, on their site they offer a bundle of jdk + netbeans ( but in this version usually you should install the C++ plugings )

  1. Go to the following link and download the bundle at : http://www.oracle.com/technetwork/java/javase/downloads/jdk-netbeans-jsp-142931.html
  2. Once installed , got the tools menu and then go to plugins
  3. If C/C++ does not figure in the installed tab , go the available plugins tab and check the C/C++ plugins and then install .

Part 4: Create and install the project