summaryrefslogtreecommitdiff
path: root/sci_gateway
diff options
context:
space:
mode:
authorHarpreet2015-08-27 02:32:30 +0530
committerHarpreet2015-08-27 02:32:30 +0530
commitf9afc284ce324fa3c13606ad90895beec507c249 (patch)
treea1680fec3342c4eb00b73cd056ff9fad519c5877 /sci_gateway
downloadFOSSEE-Optimization-toolbox-f9afc284ce324fa3c13606ad90895beec507c249.tar.gz
FOSSEE-Optimization-toolbox-f9afc284ce324fa3c13606ad90895beec507c249.tar.bz2
FOSSEE-Optimization-toolbox-f9afc284ce324fa3c13606ad90895beec507c249.zip
Master File
Diffstat (limited to 'sci_gateway')
-rw-r--r--sci_gateway/.files.txt.swpbin0 -> 12288 bytes
-rw-r--r--sci_gateway/builder_gateway.sce18
-rw-r--r--sci_gateway/cpp/.sci_sym_loadproblem.cpp.swpbin0 -> 16384 bytes
-rw-r--r--sci_gateway/cpp/builder_gateway_cpp.sce142
-rw-r--r--sci_gateway/cpp/cleaner.sce22
-rw-r--r--sci_gateway/cpp/globals.cpp101
-rw-r--r--sci_gateway/cpp/libsymphonytools.c144
-rwxr-xr-xsci_gateway/cpp/libsymphonytools.sobin0 -> 86003 bytes
-rw-r--r--sci_gateway/cpp/loader.sce78
-rw-r--r--sci_gateway/cpp/sci_iofunc.cpp194
-rw-r--r--sci_gateway/cpp/sci_iofunc.hpp19
-rw-r--r--sci_gateway/cpp/sci_solver_status_query_functions.cpp117
-rw-r--r--sci_gateway/cpp/sci_sym_addrowcol.cpp281
-rw-r--r--sci_gateway/cpp/sci_sym_getinfinity.cpp35
-rw-r--r--sci_gateway/cpp/sci_sym_getobjsense.cpp54
-rw-r--r--sci_gateway/cpp/sci_sym_getrowact.cpp68
-rw-r--r--sci_gateway/cpp/sci_sym_isenvactive.cpp47
-rw-r--r--sci_gateway/cpp/sci_sym_load_mps.cpp75
-rw-r--r--sci_gateway/cpp/sci_sym_loadproblem.cpp346
-rw-r--r--sci_gateway/cpp/sci_sym_openclose.cpp96
-rw-r--r--sci_gateway/cpp/sci_sym_primalbound.cpp87
-rw-r--r--sci_gateway/cpp/sci_sym_remove.cpp254
-rw-r--r--sci_gateway/cpp/sci_sym_rowmod.cpp192
-rw-r--r--sci_gateway/cpp/sci_sym_set_indices.cpp99
-rw-r--r--sci_gateway/cpp/sci_sym_set_variables.cpp430
-rw-r--r--sci_gateway/cpp/sci_sym_setcolsoln.cpp61
-rw-r--r--sci_gateway/cpp/sci_sym_setobj.cpp126
-rw-r--r--sci_gateway/cpp/sci_sym_solution.cpp101
-rw-r--r--sci_gateway/cpp/sci_sym_solve.cpp49
-rw-r--r--sci_gateway/cpp/sci_sym_varbounds.cpp76
-rw-r--r--sci_gateway/cpp/sci_vartype.cpp135
-rw-r--r--sci_gateway/cpp/sym_data_query_functions.cpp404
-rw-r--r--sci_gateway/cpp/template.cpp43
-rw-r--r--sci_gateway/loader_gateway.sce24
34 files changed, 3918 insertions, 0 deletions
diff --git a/sci_gateway/.files.txt.swp b/sci_gateway/.files.txt.swp
new file mode 100644
index 0000000..c00e271
--- /dev/null
+++ b/sci_gateway/.files.txt.swp
Binary files differ
diff --git a/sci_gateway/builder_gateway.sce b/sci_gateway/builder_gateway.sce
new file mode 100644
index 0000000..514d206
--- /dev/null
+++ b/sci_gateway/builder_gateway.sce
@@ -0,0 +1,18 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: Harpreet Singh
+// Organization: FOSSEE, IIT Bombay
+// Email: harpreet.mertia@gmail.com
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+sci_gateway_dir = get_absolute_file_path('builder_gateway.sce');
+
+tbx_builder_gateway_lang('cpp', sci_gateway_dir);
+tbx_build_gateway_loader(['cpp'], sci_gateway_dir);
+
+clear tbx_builder_gateway_lang tbx_build_gateway_loader;
+clear sci_gateway_dir;
diff --git a/sci_gateway/cpp/.sci_sym_loadproblem.cpp.swp b/sci_gateway/cpp/.sci_sym_loadproblem.cpp.swp
new file mode 100644
index 0000000..d71df08
--- /dev/null
+++ b/sci_gateway/cpp/.sci_sym_loadproblem.cpp.swp
Binary files differ
diff --git a/sci_gateway/cpp/builder_gateway_cpp.sce b/sci_gateway/cpp/builder_gateway_cpp.sce
new file mode 100644
index 0000000..1b8b117
--- /dev/null
+++ b/sci_gateway/cpp/builder_gateway_cpp.sce
@@ -0,0 +1,142 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: Keyur Joshi, Sai Kiran, Iswarya and Harpreet Singh
+// Organization: FOSSEE, IIT Bombay
+// Email: harpreet.mertia@gmail.com
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+mode(-1)
+lines(0)
+
+WITHOUT_AUTO_PUTLHSVAR = %t;
+toolbox_title = "symphonytools"
+
+[a, opt] = getversion();
+Version = opt(2);
+
+path_builder = get_absolute_file_path('builder_gateway_cpp.sce');
+
+tools_path = path_builder + "../../thirdparty/linux/";
+
+C_Flags=["-w -fpermissive -I"+tools_path+"include/coin -Wl,-rpath="+tools_path+"lib/"+Version+filesep()+" "]
+
+Linker_Flag = ["-L"+tools_path+"lib/"+Version+filesep()+"libSym"]
+
+//Name of All the Functions
+Function_Names = [
+ //for opening/closing environment and checking if it is open/close
+ "sym_open","sci_sym_open";
+ "sym_close","sci_sym_close";
+ "sym_isEnvActive","sci_sym_isEnvActive";
+
+ //run time parameters
+ "sym_resetParams","sci_sym_set_defaults";
+ "sym_setIntParam","sci_sym_set_int_param";
+ "sym_getIntParam","sci_sym_get_int_param";
+ "sym_setDblParam","sci_sym_set_dbl_param";
+ "sym_getDblParam","sci_sym_get_dbl_param";
+ "sym_setStrParam","sci_sym_set_str_param";
+ "sym_getStrParam","sci_sym_get_str_param";
+ "sym_getInfinity","sci_sym_getInfinity";
+
+ //problem loaders
+ "sym_loadProblemBasic","sci_sym_loadProblemBasic";
+ "sym_loadProblem","sci_sym_loadProblem";
+ "sym_loadMPS","sci_sym_load_mps";
+
+ //basic data
+ "sym_getNumConstr","sci_sym_get_num_int";
+ "sym_getNumVar","sci_sym_get_num_int";
+ "sym_getNumElements","sci_sym_get_num_int";
+
+ //variable and objective data
+ "sym_isContinuous","sci_sym_isContinuous";
+ "sym_isBinary","sci_sym_isBinary";
+ "sym_isInteger","sci_sym_isInteger";
+ "sym_setContinuous","sci_sym_set_continuous";
+ "sym_setInteger","sci_sym_set_integer";
+ "sym_getVarLower","sci_sym_get_dbl_arr";
+ "sym_getVarUpper","sci_sym_get_dbl_arr";
+ "sym_setVarLower","sci_sym_setVarBound";
+ "sym_setVarUpper","sci_sym_setVarBound";
+ "sym_getObjCoeff","sci_sym_get_dbl_arr";
+ "sym_setObjCoeff","sci_sym_setObjCoeff";
+ "sym_getObjSense","sci_sym_getObjSense";
+ "sym_setObjSense","sci_sym_setObjSense";
+
+ //constraint data
+ "sym_getRhs","sci_sym_get_dbl_arr";
+ "sym_getConstrRange","sci_sym_get_dbl_arr";
+ "sym_getConstrLower","sci_sym_get_dbl_arr";
+ "sym_getConstrUpper","sci_sym_get_dbl_arr";
+ "sym_setConstrLower","sci_sym_setConstrBound";
+ "sym_setConstrUpper","sci_sym_setConstrBound";
+ "sym_setConstrType","sci_sym_setConstrType";
+ "sym_getMatrix","sci_sym_get_matrix";
+ "sym_getConstrSense","sci_sym_get_row_sense";
+
+ //add/remove variables and constraints
+ "sym_addConstr","sci_sym_addConstr";
+ "sym_addVar","sci_sym_addVar";
+ "sym_deleteVars","sci_sym_delete_cols";
+ "sym_deleteConstrs","sci_sym_delete_rows";
+
+ //primal bound
+ "sym_getPrimalBound","sci_sym_getPrimalBound";
+ "sym_setPrimalBound","sci_sym_setPrimalBound";
+
+ //set preliminary solution
+ "sym_setVarSoln","sci_sym_setColSoln";
+
+ //solve
+ "sym_solve","sci_sym_solve";
+
+ //post solve functions
+ "sym_getStatus","sci_sym_get_status";
+ "sym_isOptimal","sci_sym_get_solver_status";
+ "sym_isInfeasible","sci_sym_get_solver_status";
+ "sym_isAbandoned","sci_sym_get_solver_status";
+ "sym_isIterLimitReached","sci_sym_get_solver_status";
+ "sym_isTimeLimitReached","sci_sym_get_solver_status";
+ "sym_isTargetGapAchieved","sci_sym_get_solver_status";
+ "sym_getVarSoln","sci_sym_getVarSoln";
+ "sym_getObjVal","sci_sym_getObjVal";
+ "sym_getIterCount","sci_sym_get_iteration_count";
+ "sym_getConstrActivity","sci_sym_getRowActivity";
+ ];
+
+//Name of all the files to be compiled
+Files = [
+ "globals.cpp",
+ "sci_iofunc.hpp",
+ "sci_iofunc.cpp",
+ "sci_sym_openclose.cpp",
+ "sci_solver_status_query_functions.cpp",
+ "sci_sym_solve.cpp",
+ "sci_sym_loadproblem.cpp",
+ "sci_sym_isenvactive.cpp",
+ "sci_sym_load_mps.cpp",
+ "sci_vartype.cpp",
+ "sci_sym_getinfinity.cpp",
+ "sci_sym_solution.cpp",
+ "sym_data_query_functions.cpp"
+ "sci_sym_set_variables.cpp",
+ "sci_sym_setobj.cpp",
+ "sci_sym_varbounds.cpp",
+ "sci_sym_rowmod.cpp",
+ "sci_sym_set_indices.cpp",
+ "sci_sym_addrowcol.cpp",
+ "sci_sym_primalbound.cpp",
+ "sci_sym_setcolsoln.cpp",
+ "sci_sym_getrowact.cpp",
+ "sci_sym_getobjsense.cpp",
+ "sci_sym_remove.cpp",
+ ]
+
+tbx_build_gateway(toolbox_title,Function_Names,Files,get_absolute_file_path("builder_gateway_cpp.sce"), [], Linker_Flag, C_Flags, [], "g++");
+
+clear WITHOUT_AUTO_PUTLHSVAR toolbox_title Function_Names Files Linker_Flag C_Flags;
diff --git a/sci_gateway/cpp/cleaner.sce b/sci_gateway/cpp/cleaner.sce
new file mode 100644
index 0000000..45a256d
--- /dev/null
+++ b/sci_gateway/cpp/cleaner.sce
@@ -0,0 +1,22 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder.sce : Please, do not edit this file
+// cleaner.sce
+// ------------------------------------------------------
+curdir = pwd();
+cleaner_path = get_file_path('cleaner.sce');
+chdir(cleaner_path);
+// ------------------------------------------------------
+if fileinfo('loader.sce') <> [] then
+ mdelete('loader.sce');
+end
+// ------------------------------------------------------
+if fileinfo('libsymphonytools.so') <> [] then
+ mdelete('libsymphonytools.so');
+end
+// ------------------------------------------------------
+if fileinfo('libsymphonytools.c') <> [] then
+ mdelete('libsymphonytools.c');
+end
+// ------------------------------------------------------
+chdir(curdir);
+// ------------------------------------------------------
diff --git a/sci_gateway/cpp/globals.cpp b/sci_gateway/cpp/globals.cpp
new file mode 100644
index 0000000..4b5d99c
--- /dev/null
+++ b/sci_gateway/cpp/globals.cpp
@@ -0,0 +1,101 @@
+/*
+ * Implementation Symphony Tool Box for Scilab
+ * globals.cpp
+ * contains definitions of global variables and functions
+ * By Keyur Joshi and Sai Kiran
+ */
+#include <symphony.h>
+#include <sciprint.h>
+
+sym_environment *global_sym_env=0;
+
+extern "C"{
+int process_ret_val(int ret_val){
+ int status=0;
+ sciprint("\n");
+ switch(ret_val){
+ case TM_NO_PROBLEM:
+ sciprint("No problem has been loaded.");
+ break;
+ case TM_NO_SOLUTION:
+ sciprint("This problem is infeasible.");
+ break;
+ case TM_FINISHED:
+ sciprint("The solver has finished working.");
+ break;
+ case TM_UNFINISHED:
+ sciprint("The solver has NOT finished working.");
+ break;
+ case TM_FEASIBLE_SOLUTION_FOUND:
+ sciprint("A feasible solution has been found. It may not be optimal.");
+ break;
+ case TM_SIGNAL_CAUGHT:
+ sciprint("TM_SIGNAL_CAUGHT");
+ break;
+ case TM_UNBOUNDED:
+ sciprint("This problem or its solution is unbounded.");
+ break;
+ case PREP_OPTIMAL_SOLUTION_FOUND:
+ sciprint("An optimal solution has been found.");
+ break;
+ case PREP_NO_SOLUTION:
+ sciprint("This problem is infeasible.");
+ break;
+ case PREP_ERROR:
+ sciprint("An error occured during preprocessing.");
+ status=1;
+ break;
+ case ERROR__USER:
+ sciprint("Error: user error detected in one of "
+ "sci_user_send_lp_data(), "
+ "sci_user_send_cg_data(), "
+ "user_send_cp_data(), "
+ "user_receive_feasible_solution(), "
+ "user_display_solution(), "
+ "user_process_own_messages() functions.");
+ status=1;
+ break;
+ case TM_OPTIMAL_SOLUTION_FOUND:
+ sciprint("An optimal solution has been found.");
+ break;
+ case TM_TIME_LIMIT_EXCEEDED:
+ sciprint("The solver stopped after the time limit was reached.");
+ break;
+ case TM_NODE_LIMIT_EXCEEDED:
+ sciprint("The solver stopped after the node limit was reached.");
+ break;
+ case TM_TARGET_GAP_ACHIEVED:
+ sciprint("The solver stopped after achieving the target gap.");
+ break;
+ case TM_FOUND_FIRST_FEASIBLE:
+ sciprint("A feasible solution has been found. It may not be optimal.");
+ break;
+ case TM_ERROR__NO_BRANCHING_CANDIDATE:
+ sciprint("Error: user didn’t select branching candidate in user_select_candidates()");
+ status=1;
+ break;
+ case TM_ERROR__ILLEGAL_RETURN_CODE:
+ sciprint("Error: illegal return code.");
+ status=1;
+ break;
+ case TM_ERROR__NUMERICAL_INSTABILITY:
+ sciprint("Error: solver stopped due to some numerical difficulties.");
+ status=1;
+ break;
+ case TM_ERROR__COMM_ERROR:
+ sciprint("Error: solver stopped due to communication error.");
+ status=1;
+ break;
+ case TM_ERROR__USER:
+ sciprint("Error: user error detected in one of user callbacks called during TM processes.");
+ break;
+ default:
+ sciprint("Error: undefined return value.");
+ status=1;
+ break;
+ }
+ sciprint("\n");
+ return status;
+}
+
+}
diff --git a/sci_gateway/cpp/libsymphonytools.c b/sci_gateway/cpp/libsymphonytools.c
new file mode 100644
index 0000000..1007284
--- /dev/null
+++ b/sci_gateway/cpp/libsymphonytools.c
@@ -0,0 +1,144 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include <mex.h>
+#include <sci_gateway.h>
+#include <api_scilab.h>
+#include <MALLOC.h>
+static int direct_gateway(char *fname,void F(void)) { F();return 0;};
+extern Gatefunc sci_sym_open;
+extern Gatefunc sci_sym_close;
+extern Gatefunc sci_sym_isEnvActive;
+extern Gatefunc sci_sym_set_defaults;
+extern Gatefunc sci_sym_set_int_param;
+extern Gatefunc sci_sym_get_int_param;
+extern Gatefunc sci_sym_set_dbl_param;
+extern Gatefunc sci_sym_get_dbl_param;
+extern Gatefunc sci_sym_set_str_param;
+extern Gatefunc sci_sym_get_str_param;
+extern Gatefunc sci_sym_getInfinity;
+extern Gatefunc sci_sym_loadProblemBasic;
+extern Gatefunc sci_sym_loadProblem;
+extern Gatefunc sci_sym_load_mps;
+extern Gatefunc sci_sym_get_num_int;
+extern Gatefunc sci_sym_get_num_int;
+extern Gatefunc sci_sym_get_num_int;
+extern Gatefunc sci_sym_isContinuous;
+extern Gatefunc sci_sym_isBinary;
+extern Gatefunc sci_sym_isInteger;
+extern Gatefunc sci_sym_set_continuous;
+extern Gatefunc sci_sym_set_integer;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_setVarBound;
+extern Gatefunc sci_sym_setVarBound;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_setObjCoeff;
+extern Gatefunc sci_sym_getObjSense;
+extern Gatefunc sci_sym_setObjSense;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_get_dbl_arr;
+extern Gatefunc sci_sym_setConstrBound;
+extern Gatefunc sci_sym_setConstrBound;
+extern Gatefunc sci_sym_setConstrType;
+extern Gatefunc sci_sym_get_matrix;
+extern Gatefunc sci_sym_get_row_sense;
+extern Gatefunc sci_sym_addConstr;
+extern Gatefunc sci_sym_addVar;
+extern Gatefunc sci_sym_delete_cols;
+extern Gatefunc sci_sym_delete_rows;
+extern Gatefunc sci_sym_getPrimalBound;
+extern Gatefunc sci_sym_setPrimalBound;
+extern Gatefunc sci_sym_setColSoln;
+extern Gatefunc sci_sym_solve;
+extern Gatefunc sci_sym_get_status;
+extern Gatefunc sci_sym_get_solver_status;
+extern Gatefunc sci_sym_get_solver_status;
+extern Gatefunc sci_sym_get_solver_status;
+extern Gatefunc sci_sym_get_solver_status;
+extern Gatefunc sci_sym_get_solver_status;
+extern Gatefunc sci_sym_get_solver_status;
+extern Gatefunc sci_sym_getVarSoln;
+extern Gatefunc sci_sym_getObjVal;
+extern Gatefunc sci_sym_get_iteration_count;
+extern Gatefunc sci_sym_getRowActivity;
+static GenericTable Tab[]={
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_open,"sym_open"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_close,"sym_close"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_isEnvActive,"sym_isEnvActive"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_set_defaults,"sym_resetParams"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_set_int_param,"sym_setIntParam"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_int_param,"sym_getIntParam"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_set_dbl_param,"sym_setDblParam"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_dbl_param,"sym_getDblParam"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_set_str_param,"sym_setStrParam"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_str_param,"sym_getStrParam"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_getInfinity,"sym_getInfinity"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_loadProblemBasic,"sym_loadProblemBasic"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_loadProblem,"sym_loadProblem"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_load_mps,"sym_loadMPS"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_num_int,"sym_getNumConstr"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_num_int,"sym_getNumVar"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_num_int,"sym_getNumElements"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_isContinuous,"sym_isContinuous"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_isBinary,"sym_isBinary"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_isInteger,"sym_isInteger"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_set_continuous,"sym_setContinuous"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_set_integer,"sym_setInteger"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_dbl_arr,"sym_getVarLower"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_dbl_arr,"sym_getVarUpper"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_setVarBound,"sym_setVarLower"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_setVarBound,"sym_setVarUpper"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_dbl_arr,"sym_getObjCoeff"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_setObjCoeff,"sym_setObjCoeff"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_getObjSense,"sym_getObjSense"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_setObjSense,"sym_setObjSense"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_dbl_arr,"sym_getRhs"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_dbl_arr,"sym_getConstrRange"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_dbl_arr,"sym_getConstrLower"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_dbl_arr,"sym_getConstrUpper"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_setConstrBound,"sym_setConstrLower"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_setConstrBound,"sym_setConstrUpper"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_setConstrType,"sym_setConstrType"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_matrix,"sym_getMatrix"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_row_sense,"sym_getConstrSense"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_addConstr,"sym_addConstr"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_addVar,"sym_addVar"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_delete_cols,"sym_deleteVars"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_delete_rows,"sym_deleteConstrs"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_getPrimalBound,"sym_getPrimalBound"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_setPrimalBound,"sym_setPrimalBound"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_setColSoln,"sym_setVarSoln"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_solve,"sym_solve"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_status,"sym_getStatus"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_solver_status,"sym_isOptimal"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_solver_status,"sym_isInfeasible"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_solver_status,"sym_isAbandoned"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_solver_status,"sym_isIterLimitReached"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_solver_status,"sym_isTimeLimitReached"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_solver_status,"sym_isTargetGapAchieved"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_getVarSoln,"sym_getVarSoln"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_getObjVal,"sym_getObjVal"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_get_iteration_count,"sym_getIterCount"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,sci_sym_getRowActivity,"sym_getConstrActivity"},
+};
+
+int C2F(libsymphonytools)()
+{
+ Rhs = Max(0, Rhs);
+ if (*(Tab[Fin-1].f) != NULL)
+ {
+ if(pvApiCtx == NULL)
+ {
+ pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));
+ }
+ pvApiCtx->pstName = (char*)Tab[Fin-1].name;
+ (*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F);
+ }
+ return 0;
+}
+#ifdef __cplusplus
+}
+#endif
diff --git a/sci_gateway/cpp/libsymphonytools.so b/sci_gateway/cpp/libsymphonytools.so
new file mode 100755
index 0000000..31e63b1
--- /dev/null
+++ b/sci_gateway/cpp/libsymphonytools.so
Binary files differ
diff --git a/sci_gateway/cpp/loader.sce b/sci_gateway/cpp/loader.sce
new file mode 100644
index 0000000..561a415
--- /dev/null
+++ b/sci_gateway/cpp/loader.sce
@@ -0,0 +1,78 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder.sce : Please, do not edit this file
+// ----------------------------------------------------------------------------
+//
+libsymphonytools_path = get_absolute_file_path('loader.sce');
+//
+// ulink previous function with same name
+[bOK, ilib] = c_link('libsymphonytools');
+if bOK then
+ ulink(ilib);
+end
+//
+list_functions = [ 'sym_open';
+ 'sym_close';
+ 'sym_isEnvActive';
+ 'sym_resetParams';
+ 'sym_setIntParam';
+ 'sym_getIntParam';
+ 'sym_setDblParam';
+ 'sym_getDblParam';
+ 'sym_setStrParam';
+ 'sym_getStrParam';
+ 'sym_getInfinity';
+ 'sym_loadProblemBasic';
+ 'sym_loadProblem';
+ 'sym_loadMPS';
+ 'sym_getNumConstr';
+ 'sym_getNumVar';
+ 'sym_getNumElements';
+ 'sym_isContinuous';
+ 'sym_isBinary';
+ 'sym_isInteger';
+ 'sym_setContinuous';
+ 'sym_setInteger';
+ 'sym_getVarLower';
+ 'sym_getVarUpper';
+ 'sym_setVarLower';
+ 'sym_setVarUpper';
+ 'sym_getObjCoeff';
+ 'sym_setObjCoeff';
+ 'sym_getObjSense';
+ 'sym_setObjSense';
+ 'sym_getRhs';
+ 'sym_getConstrRange';
+ 'sym_getConstrLower';
+ 'sym_getConstrUpper';
+ 'sym_setConstrLower';
+ 'sym_setConstrUpper';
+ 'sym_setConstrType';
+ 'sym_getMatrix';
+ 'sym_getConstrSense';
+ 'sym_addConstr';
+ 'sym_addVar';
+ 'sym_deleteVars';
+ 'sym_deleteConstrs';
+ 'sym_getPrimalBound';
+ 'sym_setPrimalBound';
+ 'sym_setVarSoln';
+ 'sym_solve';
+ 'sym_getStatus';
+ 'sym_isOptimal';
+ 'sym_isInfeasible';
+ 'sym_isAbandoned';
+ 'sym_isIterLimitReached';
+ 'sym_isTimeLimitReached';
+ 'sym_isTargetGapAchieved';
+ 'sym_getVarSoln';
+ 'sym_getObjVal';
+ 'sym_getIterCount';
+ 'sym_getConstrActivity';
+];
+addinter(libsymphonytools_path + filesep() + 'libsymphonytools' + getdynlibext(), 'libsymphonytools', list_functions);
+// remove temp. variables on stack
+clear libsymphonytools_path;
+clear bOK;
+clear ilib;
+clear list_functions;
+// ----------------------------------------------------------------------------
diff --git a/sci_gateway/cpp/sci_iofunc.cpp b/sci_gateway/cpp/sci_iofunc.cpp
new file mode 100644
index 0000000..8895010
--- /dev/null
+++ b/sci_gateway/cpp/sci_iofunc.cpp
@@ -0,0 +1,194 @@
+// Symphony Toolbox for Scilab
+// (Definition of) Functions for input and output from Scilab
+// By Keyur Joshi
+
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+
+int getDoubleFromScilab(int argNum, double *dest)
+{
+ //data declarations
+ SciErr sciErr;
+ int iRet,*varAddress;
+ const char errMsg[]="Wrong type for input argument #%d: A double is expected.\n";
+ const int errNum=999;
+ //get variable address
+ sciErr = getVarAddressFromPosition(pvApiCtx, argNum, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ //check that it is a non-complex double
+ if ( !isDoubleType(pvApiCtx,varAddress) || isVarComplex(pvApiCtx,varAddress) )
+ {
+ Scierror(errNum,errMsg,argNum);
+ return 1;
+ }
+ //retrieve and store
+ iRet = getScalarDouble(pvApiCtx, varAddress, dest);
+ if(iRet)
+ {
+ Scierror(errNum,errMsg,argNum);
+ return 1;
+ }
+ return 0;
+}
+
+int getUIntFromScilab(int argNum, int *dest)
+{
+ SciErr sciErr;
+ int iRet,*varAddress;
+ double inputDouble;
+ const char errMsg[]="Wrong type for input argument #%d: A nonnegative integer is expected.\n";
+ const int errNum=999;
+ //same steps as above
+ sciErr = getVarAddressFromPosition(pvApiCtx, argNum, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isDoubleType(pvApiCtx,varAddress) || isVarComplex(pvApiCtx,varAddress) )
+ {
+ Scierror(errNum,errMsg,argNum);
+ return 1;
+ }
+ iRet = getScalarDouble(pvApiCtx, varAddress, &inputDouble);
+ //check that an unsigned int is stored in the double by casting and recasting
+ if(iRet || ((double)((unsigned int)inputDouble))!=inputDouble)
+ {
+ Scierror(errNum,errMsg,argNum);
+ return 1;
+ }
+ *dest=(unsigned int)inputDouble;
+ return 0;
+}
+
+int getIntFromScilab(int argNum, int *dest)
+{
+ SciErr sciErr;
+ int iRet,*varAddress;
+ double inputDouble;
+ const char errMsg[]="Wrong type for input argument #%d: An integer is expected.\n";
+ const int errNum=999;
+ //same steps as above
+ sciErr = getVarAddressFromPosition(pvApiCtx, argNum, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isDoubleType(pvApiCtx,varAddress) || isVarComplex(pvApiCtx,varAddress) )
+ {
+ Scierror(errNum,errMsg,argNum);
+ return 1;
+ }
+ iRet = getScalarDouble(pvApiCtx, varAddress, &inputDouble);
+ //check that an int is stored in the double by casting and recasting
+ if(iRet || ((double)((int)inputDouble))!=inputDouble)
+ {
+ Scierror(errNum,errMsg,argNum);
+ return 1;
+ }
+ *dest=(int)inputDouble;
+ return 0;
+}
+
+int getFixedSizeDoubleMatrixFromScilab(int argNum, int rows, int cols, double **dest)
+{
+ int *varAddress,inputMatrixRows,inputMatrixCols;
+ SciErr sciErr;
+ const char errMsg[]="Wrong type for input argument #%d: A matrix of double of size %d by %d is expected.\n";
+ const int errNum=999;
+ //same steps as above
+ sciErr = getVarAddressFromPosition(pvApiCtx, argNum, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isDoubleType(pvApiCtx,varAddress) || isVarComplex(pvApiCtx,varAddress) )
+ {
+ Scierror(errNum,errMsg,argNum,rows,cols);
+ return 1;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, varAddress, &inputMatrixRows, &inputMatrixCols,NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ //check that the matrix has the correct number of rows and columns
+ if(inputMatrixRows!=rows || inputMatrixCols!=cols)
+ {
+ Scierror(errNum,errMsg,argNum,rows,cols);
+ return 1;
+ }
+ getMatrixOfDouble(pvApiCtx, varAddress, &inputMatrixRows, &inputMatrixCols, dest);
+ return 0;
+}
+
+int getDoubleMatrixFromScilab(int argNum, int *rows, int *cols, double **dest)
+{
+ int *varAddress;
+ SciErr sciErr;
+ const char errMsg[]="Wrong type for input argument #%d: A matrix of double is expected.\n";
+ const int errNum=999;
+ //same steps as above
+ sciErr = getVarAddressFromPosition(pvApiCtx, argNum, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isDoubleType(pvApiCtx,varAddress) || isVarComplex(pvApiCtx,varAddress) )
+ {
+ Scierror(errNum,errMsg,argNum);
+ return 1;
+ }
+ getMatrixOfDouble(pvApiCtx, varAddress, rows, cols, dest);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ return 0;
+}
+
+int return0toScilab()
+{
+ int iRet;
+ //create variable in scilab
+ iRet = createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx)+1,0);
+ if(iRet)
+ {
+ /* If error, no return variable */
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ return 1;
+ }
+ //make it the output variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ //return it to scilab
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+
+int returnDoubleToScilab(double retVal)
+{
+ int iRet;
+ //same steps as above
+ iRet = createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx)+1,retVal);
+ if(iRet)
+ {
+ /* If error, no return variable */
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ return 1;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
diff --git a/sci_gateway/cpp/sci_iofunc.hpp b/sci_gateway/cpp/sci_iofunc.hpp
new file mode 100644
index 0000000..1cf9a1a
--- /dev/null
+++ b/sci_gateway/cpp/sci_iofunc.hpp
@@ -0,0 +1,19 @@
+// Symphony Toolbox for Scilab
+// (Declaration of) Functions for input and output from Scilab
+// By Keyur Joshi
+
+#ifndef SCI_IOFUNCHEADER
+#define SCI_IOFUNCHEADER
+
+//input
+int getDoubleFromScilab(int argNum, double *dest);
+int getUIntFromScilab(int argNum, int *dest);
+int getIntFromScilab(int argNum, int *dest);
+int getFixedSizeDoubleMatrixFromScilab(int argNum, int rows, int cols, double **dest);
+int getDoubleMatrixFromScilab(int argNum, int *rows, int *cols, double **dest);
+
+//output
+int return0toScilab();
+int returnDoubleToScilab(double retVal);
+
+#endif //SCI_IOFUNCHEADER
diff --git a/sci_gateway/cpp/sci_solver_status_query_functions.cpp b/sci_gateway/cpp/sci_solver_status_query_functions.cpp
new file mode 100644
index 0000000..eb64bd1
--- /dev/null
+++ b/sci_gateway/cpp/sci_solver_status_query_functions.cpp
@@ -0,0 +1,117 @@
+/*
+ * Implementation of Symphony Tool Box for Scilab
+ * solver_status_query_functions.cpp
+ * contains Solver Status Query Functions (7 functions)
+ * Author: Sai Kiran
+ */
+
+#include <symphony.h>
+#include <sci_iofunc.hpp>
+extern sym_environment* global_sym_env;//defined in globals.cpp
+
+extern "C" {
+#include <api_scilab.h>
+#include <Scierror.h>
+#include <BOOL.h>
+#include <localization.h>
+#include <sciprint.h>
+#include <string.h>
+
+int process_ret_val(int);
+
+/*
+ * This function returns the status of problem that has been solved.
+ */
+int sci_sym_get_status(char *fname, unsigned long fname_len){
+
+ int status=0;
+
+ //check whether we have no input and one output argument or not
+ CheckInputArgument(pvApiCtx, 0, 0) ;//no input argument
+ CheckOutputArgument(pvApiCtx, 1, 1) ;//one output argument
+
+ // Check environment
+ if(global_sym_env==NULL)
+ sciprint("Error: Symphony environment is not initialized.\n");
+ else // There is an environment opened
+ status=sym_get_status(global_sym_env);// Call function
+ // Return result to scilab
+ return returnDoubleToScilab(status);
+ }
+
+
+/* This is a generelized function for
+ * sym_isOptimal,sym_isInfeasible,sym_isAbandoned,
+ * sym_isIterLimitReached,sym_isTimeLimitReached,
+ * and sym_isTargetGapAchieved.
+ * All the above functions have same return value and input argument.
+ *
+ * It returns (to scilab)
+ * 1 if the function is proved true.
+ * 0 if the function is proved false.
+ * -1 if there is an error.
+ */
+int sci_sym_get_solver_status(char *fname, unsigned long fname_len){
+ int result= -1 ;// Result to caller. Set to error.
+
+ // Check whether we have no input and one output argument or not
+ CheckInputArgument(pvApiCtx, 0, 0) ;// No input argument
+
+ // One output argument (For scilab 1 o/p argument is fixed)
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ /* Array of possible callers of this function */
+ char *arr_caller[]={"sym_isOptimal","sym_isInfeasible","sym_isAbandoned",
+ "sym_isIterLimitReached","sym_isTimeLimitReached",
+ "sym_isTargetGapAchieved" };
+
+ /* Array of functions to be called */
+ int (*fun[])(sym_environment *)= { sym_is_proven_optimal,
+ sym_is_proven_primal_infeasible,
+ sym_is_abandoned,sym_is_iteration_limit_reached,
+ sym_is_time_limit_reached,sym_is_target_gap_achieved
+ };
+ /* Output values if functions return TRUE */
+ char *output_true[] = {"The problem is solved to optimality.",
+ "The problem is proved to be infeasible.",
+ "The problem is abandoned.",
+ "Iteration limit is reached.",
+ "Time limit is reached.","Target gap is reached."};
+
+ /* Output values if functions return FALSE */
+ char *output_false[] = {"The problem is not solved to optimality.",
+ "The problem is not proved to be infeasible.",
+ "The problem is not abandoned.",
+ "Iteration limit is not reached.",
+ "Time limit is not reached.","Target gap is not reached."};
+ // Check environment
+ if(global_sym_env==NULL)
+ sciprint("Error: Symphony environment is not initialized.\n");
+ else {//there is an environment opened
+ int iter = 0, length= sizeof(arr_caller) / sizeof(char *),found_at= -1;
+
+ for (;iter < length ;++iter)
+ if (!strcmp(fname,arr_caller[iter])) //Find caller
+ found_at=iter;
+ if (found_at != -1 ) {
+ result = fun[found_at](global_sym_env);
+ sciprint("\n");
+ switch (result) {
+ case TRUE: // TRUE = 1
+ sciprint(output_true[found_at]);
+ break;
+ case FALSE: // FALSE = 0
+ sciprint(output_false[found_at]);
+ break;
+ default:
+ sciprint("Undefined return value.");
+ result = -1;
+ }
+ sciprint("\n");
+ }
+ else // Very rare case
+ sciprint("\nError in function mapping in scilab script\n");
+ }
+ return returnDoubleToScilab(result);
+ }
+}
diff --git a/sci_gateway/cpp/sci_sym_addrowcol.cpp b/sci_gateway/cpp/sci_sym_addrowcol.cpp
new file mode 100644
index 0000000..4e1d76e
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_addrowcol.cpp
@@ -0,0 +1,281 @@
+/*
+ * Symphony Toolbox
+ * Functions to add a new row or column
+ * By Keyur Joshi
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+
+int sci_sym_addConstr(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ int *varAddress,numVars,nonZeros,*itemsPerRow,*colIndex,inputRows,inputCols,colIter;
+ double inputDouble,*matrix,conRHS,conRHS2,conRange;
+ char conType,*conTypeInput;
+ bool isRangedConstr=false;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,3,4) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //get number of columns
+ iRet=sym_get_num_cols(global_sym_env,&numVars);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }
+
+ //get input 1: sparse matrix of variable coefficients in new constraint
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isSparseType(pvApiCtx,varAddress) || isVarComplex(pvApiCtx,varAddress) )
+ {
+ Scierror(999, "Wrong type for input argument #1: A sparse matrix of doubles is expected.\n");
+ return 1;
+ }
+ sciErr = getSparseMatrix(pvApiCtx,varAddress,&inputRows,&inputCols,&nonZeros,&itemsPerRow,&colIndex,&matrix);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if(inputRows!=1 || inputCols!=numVars)
+ {
+ Scierror(999, "Wrong type for input argument #1: Incorrectly sized matrix.\n");
+ return 1;
+ }
+ //scilab has 1-based column indices, convert to 0-based for Symphony
+ for(colIter=0;colIter<nonZeros;colIter++)
+ colIndex[colIter]--;
+
+ //get argument 2: type of constraint
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isStringType(pvApiCtx,varAddress) )
+ {
+ Scierror(999, "Wrong type for input argument #2: Either \"L\", \"E\", \"G\", or \"R\" is expected.\n");
+ return 1;
+ }
+ iRet = getAllocatedSingleString(pvApiCtx, varAddress, &conTypeInput);
+ if(iRet)
+ {
+ Scierror(999, "Wrong type for input argument #2: Either \"L\", \"E\", \"G\", or \"R\" is expected.\n");
+ return 1;
+ }
+ switch(conTypeInput[0]){
+ case 'l':case 'L':
+ conType='L';
+ break;
+ case 'e':case 'E':
+ conType='E';
+ break;
+ case 'g':case 'G':
+ conType='G';
+ break;
+ case 'r':case 'R':
+ conType='R';
+ isRangedConstr=true;
+ break;
+ default:
+ Scierror(999, "Wrong type for input argument #2: Either \"L\", \"E\", \"G\", or \"R\" is expected.\n");
+ return 1;
+ }
+ //check number of arguments for specific cases
+ if(isRangedConstr){
+ if(nbInputArgument(pvApiCtx)!=4){
+ Scierror(999, "4 Arguments are expected for ranged constraint.\n");
+ return 1;
+ }
+ }else if(nbInputArgument(pvApiCtx)!=3){
+ Scierror(999, "3 Arguments are expected for non-ranged constraint.\n");
+ return 1;
+ }
+
+ //get argument 3: constraint RHS
+ if(getDoubleFromScilab(3,&conRHS))
+ return 1;
+
+ //get argument 4: constraint range
+ if(isRangedConstr){
+ if(getDoubleFromScilab(4,&conRHS2))
+ return 1;
+ //conRHS should be the upper bound, and conRange should be positive
+ if(conRHS>=conRHS2){
+ conRange=conRHS-conRHS2;
+ }else{
+ conRange=conRHS2-conRHS;
+ conRHS=conRHS2;
+ }
+ }else{
+ //if not ranged constraint, just set it to 0, the value probably does not matter anyway
+ conRange=0;
+ }
+
+ iRet=sym_add_row(global_sym_env,nonZeros,colIndex,matrix,conType,conRHS,conRange);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured.\n");
+ return 1;
+ }else{
+ sciprint("Constraint successfully added.\n");
+ }
+
+ //code to give output
+ if(return0toScilab())
+ return 1;
+
+ return 0;
+}
+
+int sci_sym_addVar(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ int *varAddress,numConstr,nonZeros,*itemsPerRow,*colIndex,*rowIndex,inputRows,inputCols,rowIter,arrayIter,isInt;
+ double inputDouble,*matrix,uBound,lBound,objCoeff;
+ char *varName,isIntChar;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,6,6) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //get number of rows
+ iRet=sym_get_num_rows(global_sym_env,&numConstr);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }
+
+ //get input 1: sparse matrix of new variable coefficients constraints
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isSparseType(pvApiCtx,varAddress) || isVarComplex(pvApiCtx,varAddress) )
+ {
+ Scierror(999, "Wrong type for input argument #1: A sparse matrix of doubles is expected.\n");
+ return 1;
+ }
+ sciErr = getSparseMatrix(pvApiCtx,varAddress,&inputRows,&inputCols,&nonZeros,&itemsPerRow,&colIndex,&matrix);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if(inputRows!=numConstr || inputCols!=1)
+ {
+ Scierror(999, "Wrong type for input argument #1: Incorrectly sized matrix.\n");
+ return 1;
+ }
+
+ //get argument 2: lower bound of new variable
+ if(getDoubleFromScilab(2,&lBound))
+ return 1;
+
+ //get argument 3: upper bound of new variable
+ if(getDoubleFromScilab(3,&uBound))
+ return 1;
+
+ //get argument 4: coefficient of new variable in objective
+ if(getDoubleFromScilab(4,&objCoeff))
+ return 1;
+
+ //get argument 5: wether the variable is constrained to be an integer
+ sciErr = getVarAddressFromPosition(pvApiCtx, 5, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isBooleanType(pvApiCtx, varAddress) )
+ {
+ Scierror(999, "Wrong type for input argument #5: A boolean is expected.\n");
+ return 1;
+ }
+ iRet = getScalarBoolean(pvApiCtx, varAddress, &isInt);
+ if(iRet)
+ {
+ Scierror(999, "Wrong type for input argument #5: A boolean is expected.\n");
+ return 1;
+ }
+ isIntChar=isInt?TRUE:FALSE;
+
+ //get argument 6: name of new variable
+ sciErr = getVarAddressFromPosition(pvApiCtx, 6, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isStringType(pvApiCtx,varAddress) )
+ {
+ Scierror(999, "Wrong type for input argument #6: A string is expected.\n");
+ return 1;
+ }
+ iRet = getAllocatedSingleString(pvApiCtx, varAddress, &varName);
+ if(iRet)
+ {
+ Scierror(999, "Wrong type for input argument #6: A string is expected.\n");
+ return 1;
+ }
+
+ //convert to form required by Symphony
+ rowIndex=new int[nonZeros];
+ for(rowIter=0,arrayIter=0;rowIter<numConstr;rowIter++)
+ if(itemsPerRow[rowIter])
+ rowIndex[arrayIter++]=rowIter;
+
+ iRet=sym_add_col(global_sym_env,nonZeros,rowIndex,matrix,lBound,uBound,objCoeff,isIntChar,varName);
+ delete[] rowIndex;
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured.\n");
+ return 1;
+ }else{
+ sciprint("Variable successfully added.\n");
+ }
+
+ //code to give output
+ if(return0toScilab())
+ return 1;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_sym_getinfinity.cpp b/sci_gateway/cpp/sci_sym_getinfinity.cpp
new file mode 100644
index 0000000..c7fe243
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_getinfinity.cpp
@@ -0,0 +1,35 @@
+/*
+ * Symphony Toolbox
+ * Provides the Symphony infinity value
+ * By Keyur Joshi
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+
+int sci_sym_getInfinity(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,0,0) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //code to give output
+ if(returnDoubleToScilab(sym_get_infinity()))
+ return 1;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_sym_getobjsense.cpp b/sci_gateway/cpp/sci_sym_getobjsense.cpp
new file mode 100644
index 0000000..3df325c
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_getobjsense.cpp
@@ -0,0 +1,54 @@
+/*
+ * Symphony Toolbox
+ * <Description>
+ * <Author(s)>
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+
+int sci_sym_getObjSense(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ int objSense;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,0,0) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //code to give output
+ iRet=sym_get_obj_sense(global_sym_env,&objSense);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }
+ if(objSense==1)
+ sciprint("Symphony has been set to minimize the objective.\n");
+ else
+ sciprint("Symphony has been set to maximize the objective.\n");
+
+ if(returnDoubleToScilab(objSense))
+ return 1;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_sym_getrowact.cpp b/sci_gateway/cpp/sci_sym_getrowact.cpp
new file mode 100644
index 0000000..fac3ddf
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_getrowact.cpp
@@ -0,0 +1,68 @@
+/*
+ * Symphony Toolbox
+ * Function to get the row activity after solving
+ * By Keyur Joshi
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+
+int sci_sym_getRowActivity(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ int numConstr;
+ double *rowAct;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,0,0) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //code to process input
+ iRet=sym_get_num_rows(global_sym_env,&numConstr);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has the problem been solved? Is the problem feasible?\n");
+ return 1;
+ }
+ rowAct=new double[numConstr];
+ iRet=sym_get_row_activity(global_sym_env,rowAct);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has the problem been solved? Is the problem feasible?\n");
+ delete[] rowAct;
+ return 1;
+ }
+
+ //code to give output
+ sciErr=createMatrixOfDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,numConstr,1,rowAct);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ delete[] rowAct;
+ return 1;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ ReturnArguments(pvApiCtx);
+
+ delete[] rowAct;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_sym_isenvactive.cpp b/sci_gateway/cpp/sci_sym_isenvactive.cpp
new file mode 100644
index 0000000..96d5976
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_isenvactive.cpp
@@ -0,0 +1,47 @@
+/*
+ * Symphony Toolbox
+ * Check if Symphony environment is active
+ * Made by Keyur Joshi
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+
+int sci_sym_isEnvActive(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ double returnVal;
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,0,0) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //code to process input
+ if(global_sym_env==NULL){
+ sciprint("Symphony environment is not initialized. Please run 'sym_open()' first.\n");
+ returnVal=0.0;
+ }else{
+ sciprint("Symphony environment is active and ready for use.\n");
+ returnVal=1.0;
+ }
+
+ //code to give output
+ if(returnDoubleToScilab(returnVal))
+ return 1;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_sym_load_mps.cpp b/sci_gateway/cpp/sci_sym_load_mps.cpp
new file mode 100644
index 0000000..7f000fb
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_load_mps.cpp
@@ -0,0 +1,75 @@
+/*
+ * Implementation Symphony Tool Box for Scilab
+ * template.cpp
+ * contains function for loading .mps file to symphony
+ * By Iswarya
+ */
+#include <symphony.h>
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env;//defined in globals.cpp
+
+extern "C"{
+#include <api_scilab.h>
+#include <Scierror.h>
+#include <BOOL.h>
+#include <localization.h>
+#include <sciprint.h>
+
+//This function is for loading a mps file to symphony
+int sci_sym_load_mps(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr;
+
+ //data declarations
+ double status=1.0;//assume error status
+ int *piAddressVarOne = NULL;//pointer used to access argument of the function
+ char file[100];//string to hold the name of .mps file
+ char* ptr=file;//pointer to point to address of file name
+ int output=0;//out parameter for the load mps function
+ CheckInputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument as input or not
+ CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument on output side or not
+
+ //load address of 1st argument into piAddressVarOne
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
+
+ //check whether there is an error or not.
+ if (sciErr.iErr){
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isStringType(pvApiCtx,piAddressVarOne) )
+ {
+ Scierror(999,"Wrong type for input argument 1: A file name is expected.\n");
+ return 1;
+ }
+
+ //read the value in that pointer pointing to file name
+ int err=getAllocatedSingleString(pvApiCtx, piAddressVarOne, &ptr);
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ }else{
+ output=sym_read_mps(global_sym_env,ptr);//loading .mps file to symphony
+ if(output==FUNCTION_TERMINATED_ABNORMALLY || output==ERROR__READING_MPS_FILE)
+ {
+ status=1.0;//function did not invoke successfully
+ sciprint("Error while reading file\n");
+ }
+ else if(output==FUNCTION_TERMINATED_NORMALLY)
+ {
+ status=0.0;//no error in executing the function
+ sciprint("File read successfully\n");
+ }
+ }
+
+ if(returnDoubleToScilab(status))
+ return 1;
+
+ return 0;
+}
+
+}
+
diff --git a/sci_gateway/cpp/sci_sym_loadproblem.cpp b/sci_gateway/cpp/sci_sym_loadproblem.cpp
new file mode 100644
index 0000000..6d7f538
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_loadproblem.cpp
@@ -0,0 +1,346 @@
+/*
+ * Symphony Toolbox
+ * Explicit problem loaders
+ * Made by Keyur Joshi
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+#include <string.h>
+
+//error management variables
+static SciErr sciErr;
+static int iRet;
+
+//data declarations
+static int *varAddress=NULL,numVars,numConstr,*conMatrixColStart=NULL,*conMatrixRowIndex=NULL,*isIntVarBool=NULL,colIter,rowIter,inputMatrixCols,inputMatrixRows;
+static double inputDouble,objSense,*objective=NULL,*lowerBounds=NULL,*upperBounds=NULL,*conLower=NULL,*conUpper=NULL,*conRange=NULL,*conRHS=NULL,*conMatrix=NULL;
+static char *conType=NULL,*isIntVar=NULL;
+
+//delete all allocd arrays before exit, and return output argument
+static void cleanupBeforeExit()
+ {
+ if(conMatrixColStart) delete[] conMatrixColStart;
+ if(conMatrixRowIndex) delete[] conMatrixRowIndex;
+ if(isIntVar) delete[] isIntVar;
+ if(conType) delete[] conType;
+ if(conRange) delete[] conRange;
+ if(conRHS) delete[] conRHS;
+ iRet = createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx)+1,0);
+ if(iRet)
+ {
+ /* If error, no return variable */
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ return;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ ReturnArguments(pvApiCtx);
+}
+
+static int checkNumArgs()
+{
+ CheckInputArgument(pvApiCtx,10,10);
+ CheckOutputArgument(pvApiCtx,1,1);
+ return 1;
+}
+
+//both basic and advanced loader use this code
+static int commonCodePart1()
+{
+
+ //ensure that environment is active
+ if(global_sym_env==NULL)
+ {
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ if(checkNumArgs()==0)
+ return 1;
+
+ //get input 1: number of variables
+ if(getUIntFromScilab(1,&numVars))
+ return 1;
+
+ //get input 2: number of constraints
+ if(getUIntFromScilab(2,&numConstr))
+ return 1;
+
+ //allocate and prepare some arrays
+ isIntVar=new char[numVars]; //is the variable constrained to be an integer?
+ conType=new char[numConstr]; //char representing constraint type
+ conRange=new double[numConstr]; //range of each constraint
+ conRHS=new double[numConstr]; //RHS to be given to Symphony
+
+ return 0;
+}
+
+//both basic and advanced loader use this code
+static int commonCodePart2()
+{
+ //get input 3: lower bounds of variables
+ if(getFixedSizeDoubleMatrixFromScilab(3,1,numVars,&lowerBounds))
+ {
+ cleanupBeforeExit();
+ return 1;
+ }
+
+ //get input 4: upper bounds of variables
+ if(getFixedSizeDoubleMatrixFromScilab(4,1,numVars,&upperBounds))
+ {
+ cleanupBeforeExit();
+ return 1;
+ }
+
+ //get input 5: coefficients of variables in objective function to be minimized
+ if(getFixedSizeDoubleMatrixFromScilab(5,1,numVars,&objective))
+ {
+ cleanupBeforeExit();
+ return 1;
+ }
+
+ //get input 6: array that specifies wether a variable is constrained to be an integer
+ sciErr = getVarAddressFromPosition(pvApiCtx, 6, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ cleanupBeforeExit();return 1;
+ }
+ if ( !isBooleanType(pvApiCtx, varAddress) )
+ {
+ Scierror(999, "Wrong type for input argument #6: A matrix of booleans is expected.\n");
+ cleanupBeforeExit();return 1;
+ }
+ sciErr = getMatrixOfBoolean(pvApiCtx, varAddress, &inputMatrixRows, &inputMatrixCols, &isIntVarBool);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ cleanupBeforeExit();return 1;
+ }
+ if(inputMatrixRows!=1 || inputMatrixCols!=numVars)
+ {
+ Scierror(999, "Wrong type for input argument #6: Incorrectly sized matrix.\n");
+ cleanupBeforeExit();return 1;
+ }
+ for(colIter=0;colIter<numVars;colIter++)
+ {
+ if(isIntVarBool[colIter])
+ isIntVar[colIter]=TRUE;
+ else
+ isIntVar[colIter]=FALSE;
+ }
+
+ //get input 7: wether to minimize or maximize objective
+ sciErr = getVarAddressFromPosition(pvApiCtx, 7, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isDoubleType(pvApiCtx,varAddress) || isVarComplex(pvApiCtx,varAddress) )
+ {
+ Scierror(999, "Wrong type for input argument #7: Either 1 (sym_minimize) or -1 (sym_maximize) is expected.\n");
+ return 1;
+ }
+ iRet = getScalarDouble(pvApiCtx, varAddress, &objSense);
+ if(iRet || (objSense!=-1 && objSense!=1))
+ {
+ Scierror(999, "Wrong type for input argument #7: Either 1 (sym_minimize) or -1 (sym_maximize) is expected.\n");
+ return 1;
+ }
+ iRet=sym_set_obj_sense(global_sym_env,objSense);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY)
+ {
+ Scierror(999, "An error occured.\n");
+ return 1;
+ }
+
+ //get input 9: constraint lower bound
+ if(!(numConstr == 0))
+ {
+ if(getFixedSizeDoubleMatrixFromScilab(9,numConstr,1,&conLower) )
+ {
+ cleanupBeforeExit();
+ return 1;
+ }
+ }
+ //get input 10: constraint upper bound
+ if(!(numConstr == 0))
+ {
+ if(getFixedSizeDoubleMatrixFromScilab(10,numConstr,1,&conUpper) && (numConstr == 0) )
+ {
+ cleanupBeforeExit();
+ return 1;
+ }
+ }
+ //deduce type of constraint
+ for(rowIter=0;rowIter<numConstr;rowIter++)
+ {
+ if(conLower[rowIter]>conUpper[rowIter])
+ {
+ Scierror(999, "Error: the lower bound of constraint %d is more than its upper bound.\n",rowIter);
+ cleanupBeforeExit();
+ return 1;
+ }
+ if(conLower[rowIter]==(-INFINITY) && conUpper[rowIter]==INFINITY){
+ conType[rowIter]='N';
+ conRange[rowIter]=0;
+ conRHS[rowIter]=0;
+ }else if(conLower[rowIter]==(-INFINITY)){
+ conType[rowIter]='L';
+ conRange[rowIter]=0;
+ conRHS[rowIter]=conUpper[rowIter];
+ }else if(conUpper[rowIter]==INFINITY){
+ conType[rowIter]='G';
+ conRange[rowIter]=0;
+ conRHS[rowIter]=conLower[rowIter];
+ }else if(conUpper[rowIter]==conLower[rowIter]){
+ conType[rowIter]='E';
+ conRange[rowIter]=0;
+ conRHS[rowIter]=conLower[rowIter];
+ }else{
+ conType[rowIter]='R';
+ conRange[rowIter]=conUpper[rowIter]-conLower[rowIter];
+ conRHS[rowIter]=conUpper[rowIter];
+ }
+ }
+
+ /*
+ //for debug: show all data
+ sciprint("Vars: %d Constr: %d ObjType: %lf\n",numVars,numConstr,objSense);
+ for(colIter=0;colIter<numVars;colIter++)
+ sciprint("Var %d: upper: %lf lower: %lf isInt: %d ObjCoeff: %lf\n",colIter,lowerBounds[colIter],upperBounds[colIter],isIntVar[colIter],objective[colIter]);
+ for(rowIter=0;rowIter<numConstr;rowIter++)
+ sciprint("Constr %d: type: %c lower: %lf upper: %lf range: %lf\n",rowIter,conType[rowIter],conLower[rowIter],conRange[rowIter]);
+ */
+
+ //call problem loader
+ sym_explicit_load_problem(global_sym_env,numVars,numConstr,conMatrixColStart,conMatrixRowIndex,conMatrix,lowerBounds,upperBounds,isIntVar,objective,NULL,conType,conRHS,conRange,TRUE);
+ sciprint("Problem loaded into environment.\n");
+
+ //code to give output
+ cleanupBeforeExit();
+
+ return 0;
+}
+
+//basic problem loader, expects normal matrix. Not suitable for large problems
+int sci_sym_loadProblemBasic(char *fname)
+{
+
+ if(commonCodePart1())
+ return 1;
+
+ if(!(numConstr == 0))
+ {
+ //get input 8: matrix of constraint equation coefficients
+
+ if(getFixedSizeDoubleMatrixFromScilab(8,numConstr,numVars,&conMatrix) )
+ {
+ cleanupBeforeExit();
+ return 1;
+ }
+ }
+
+ conMatrixColStart=new int[numVars+1]; //start of each column of constraint matrix, used internally
+ conMatrixRowIndex=new int[numVars*numConstr]; //index of column elements in each column, used internally
+ for(colIter=0;colIter<numVars;colIter++)
+ {
+ conMatrixColStart[colIter]=colIter*numConstr;
+ for(rowIter=0;rowIter<numConstr;rowIter++)
+ {
+ conMatrixRowIndex[colIter*numConstr+rowIter]=rowIter;
+ }
+ }
+ conMatrixColStart[numVars]=numVars*numConstr;
+
+ if(commonCodePart2())
+ return 1;
+
+ return 0;
+}
+
+//advanced problem loader, expects sparse matrix. For use with larger problems (>10 vars)
+int sci_sym_loadProblem(char *fname)
+{
+ int retVal,nonZeros,*itemsPerRow,*colIndex,matrixIter,newPos,*oldRowIndex,*colStartCopy;
+ double *data;
+
+ if(commonCodePart1())
+ return 1;
+
+ //get input 8: matrix of constraint equation coefficients
+ sciErr = getVarAddressFromPosition(pvApiCtx, 8, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ cleanupBeforeExit();return 1;
+ }
+
+ if(!(numConstr == 0))
+ {
+
+ if ( (!isSparseType(pvApiCtx,varAddress) || isVarComplex(pvApiCtx,varAddress)) && (numConstr == 0))
+ {
+ Scierror(999, "Wrong type for input argument #8: A sparse matrix of doubles is expected.\n");
+ cleanupBeforeExit();return 1;
+ }
+ }
+ sciErr = getSparseMatrix(pvApiCtx,varAddress,&inputMatrixRows,&inputMatrixCols,&nonZeros,&itemsPerRow,&colIndex,&data);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ cleanupBeforeExit();return 1;
+ }
+ if(inputMatrixRows!=numConstr || inputMatrixCols!=numVars)
+ {
+ Scierror(999, "Wrong type for input argument #8: Incorrectly sized matrix.\n");
+ cleanupBeforeExit();return 1;
+ }
+
+ //convert SciLab format sparse matrix into the format required by Symphony
+ conMatrix=new double[nonZeros]; //matrix contents
+ conMatrixColStart=new int[numVars+1]; //where each column of the matrix starts
+ conMatrixRowIndex=new int[nonZeros]; //row number of each element
+ oldRowIndex=new int[nonZeros]; //row number in old matrix
+ colStartCopy=new int[numVars+1]; //temporary copy of conMatrixColStart
+ for(rowIter=matrixIter=0;rowIter<numConstr;rowIter++) //assign row number to each element in old matrix
+ for(colIter=0;colIter<itemsPerRow[rowIter];colIter++,matrixIter++)
+ oldRowIndex[matrixIter]=rowIter;
+ for(colIter=0;colIter<=numVars;colIter++) //initialize to 0
+ conMatrixColStart[colIter]=0;
+ for(matrixIter=0;matrixIter<nonZeros;matrixIter++) //get number of elements in each column
+ conMatrixColStart[colIndex[matrixIter]]++;
+ for(colIter=1;colIter<=numVars;colIter++) //perfrom cumulative addition to get final data about where each column starts
+ {
+ conMatrixColStart[colIter]+=conMatrixColStart[colIter-1];
+ colStartCopy[colIter]=conMatrixColStart[colIter];
+ }
+ colStartCopy[0]=0;
+ for(matrixIter=0;matrixIter<nonZeros;matrixIter++) //move data from old matrix to new matrix
+ {
+ newPos=colStartCopy[colIndex[matrixIter]-1]++; //calculate its position in the new matrix
+ conMatrix[newPos]=data[matrixIter]; //move the data
+ conMatrixRowIndex[newPos]=oldRowIndex[matrixIter]; //assign it its row number
+ }
+
+ retVal=commonCodePart2();
+
+ //cleanup some more allocd memory
+ if(conMatrix) delete[] conMatrix;
+ if(oldRowIndex) delete[] oldRowIndex;
+ if(colStartCopy) delete[] colStartCopy;
+
+ return retVal;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_sym_openclose.cpp b/sci_gateway/cpp/sci_sym_openclose.cpp
new file mode 100644
index 0000000..4bab3e1
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_openclose.cpp
@@ -0,0 +1,96 @@
+/*
+ * Symphony Tool Box for Scilab
+ * contains functions that opens and closes the symphony environment
+ * By Keyur Joshi, Iswarya
+ */
+#include <symphony.h>
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env;//defined in globals.cpp
+
+extern "C" {
+#include <api_scilab.h>
+#include <Scierror.h>
+#include <BOOL.h>
+#include <localization.h>
+#include <sciprint.h>
+
+/* Function that initializes the symphony environment
+ * Returns 1 on success , 0 on failure
+ */
+int sci_sym_open(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr;
+ double status=0;
+
+ //check whether we have no input and one output argument or not
+ CheckInputArgument(pvApiCtx, 0, 0) ;//no input argument
+ CheckOutputArgument(pvApiCtx, 1, 1) ;//one output argument
+
+ //check environment
+ if(global_sym_env!=NULL){
+ sciprint("Warning: Symphony environment is already initialized.\n");
+ }else{
+ global_sym_env = sym_open_environment();//open an environment
+ if (!global_sym_env)
+ sciprint("Error: Unable to create symphony environment.\n");
+ else{
+ status=1;
+ //sciprint("Symphony environment is created successfully. Please run 'sym_close()' to close.\n");
+ //create useful variables for user
+ createNamedScalarDouble(pvApiCtx,"sym_minimize",1);
+ createNamedScalarDouble(pvApiCtx,"sym_maximize",-1);
+ }
+ }
+
+ /*write satus of function (success-1 or failure-0) as output argument to scilab*/
+ if(returnDoubleToScilab(status))
+ return 1;
+
+ return 0;
+}
+
+/*Function that closes symphony environment
+ * Returns 1 on success , 0 on failure
+*/
+int sci_sym_close(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr;
+ double status=0;
+ int output;//output parameter for closing the environment
+
+
+ //check whether we have no input and one output argument or not
+ CheckInputArgument(pvApiCtx, 0, 0) ;//no input argument
+ CheckOutputArgument(pvApiCtx, 1, 1) ;//one output argument
+
+ if (global_sym_env==NULL){//check for environment
+ sciprint("Error: symphony environment is not initialized.\n");
+ }else{
+ output=sym_close_environment(global_sym_env);//close environment
+ if(output==ERROR__USER){
+ status=0;//User error detected in user_free_master() function or when function invoked unsuccessfully
+ sciprint("Error in user_free_master()\n");
+ }else if(output==FUNCTION_TERMINATED_ABNORMALLY){
+ status=0;//function invoked unsuccessfully
+ sciprint("Symphony environment could not be closed.\n");
+ }else if(output==FUNCTION_TERMINATED_NORMALLY){
+ status=1;//function invoked successfully and no error
+ global_sym_env=NULL;//important to set to NULL, so that other functions can detect that environment is not open.
+ //sciprint("Symphony environement closed successfully. Please run 'sym_open()' to restart.\n");
+ //delete the sym_ variables
+ deleteNamedVariable(pvApiCtx,"sym_minimize");
+ deleteNamedVariable(pvApiCtx,"sym_maximize");
+ }
+ }
+
+ /*write satus of function (success-1 or failure-0) as output argument to scilab*/
+ if(returnDoubleToScilab(status))
+ return 1;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_sym_primalbound.cpp b/sci_gateway/cpp/sci_sym_primalbound.cpp
new file mode 100644
index 0000000..7e79d87
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_primalbound.cpp
@@ -0,0 +1,87 @@
+/*
+ * Symphony Toolbox
+ * Functions for getting/setting the primal bound
+ * By Keyur Joshi
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+
+int sci_sym_getPrimalBound(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ double retVal;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,0,0) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //code to process input
+ iRet=sym_get_primal_bound(global_sym_env,&retVal);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has the problem been loaded?\n");
+ return 1;
+ }
+
+ //code to give output
+ if(returnDoubleToScilab(retVal))
+ return 1;
+
+ return 0;
+}
+
+int sci_sym_setPrimalBound(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ double bound;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,1,1) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //code to process input
+ if(getDoubleFromScilab(1,&bound))
+ return 1;
+
+ iRet=sym_set_primal_bound(global_sym_env,bound);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has the problem been loaded?\n");
+ return 1;
+ }
+
+ //code to give output
+ if(return0toScilab())
+ return 1;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_sym_remove.cpp b/sci_gateway/cpp/sci_sym_remove.cpp
new file mode 100644
index 0000000..d4e9c49
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_remove.cpp
@@ -0,0 +1,254 @@
+/*
+ * Implementation Symphony Tool Box for Scilab
+ * set_sym_remove.cpp
+ * contains function for removing columns and rows
+ * By Iswarya
+ */
+#include <symphony.h>
+
+extern sym_environment* global_sym_env;//defined in globals.cpp
+
+extern "C" {
+#include <api_scilab.h>
+#include <Scierror.h>
+#include <BOOL.h>
+#include <localization.h>
+#include <sciprint.h>
+//function to remove specified columns
+int sci_sym_delete_cols(char *fname, unsigned long fname_len){
+
+ // Error management variables
+ SciErr sciErr1,sciErr2;
+ double status=1.0;//assume error status
+ double num;//variable to store the number of columns to be deleted obtained from user in scilab
+ int count=0;//iterator variable
+ int num_cols;//stores the number of columns in the loaded problem
+ int iType= 0;//stores the datatype of matrix
+ int rows=0,columns=0;//integer variables to denote the number of rows and columns in the array denoting the column numbers to be deleted
+ unsigned int *value=NULL;//pointer to integer array allocated dynamically having the indices to be deleted
+ double *array_ptr=NULL;//double array pointer to the array denoting the column numbers to be deleted
+ int *piAddressVarOne = NULL;//pointer used to access first and second arguments of the function
+ int output=0;//output parameter for the symphony sym_delete_cols function
+ CheckInputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument as input or not
+ CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument on output side or not
+
+ //load address of 1st argument into piAddressVarOne
+ sciErr2=getVarAddressFromPosition(pvApiCtx,1,&piAddressVarOne);
+
+
+ if (sciErr2.iErr){
+ printError(&sciErr2, 0);
+ return 0;
+ }
+
+ //check if it is double type
+ sciErr2 = getVarType(pvApiCtx, piAddressVarOne, &iType);
+ if(sciErr2.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr2, 0);
+ return 0;
+ }
+
+
+ //getting the first argument as a double array
+ sciErr2=getMatrixOfDouble(pvApiCtx,piAddressVarOne,&rows,&columns,&array_ptr);
+ if (sciErr2.iErr){
+ printError(&sciErr2, 0);
+ return 0;
+ }
+
+ //dynamically allocate the integer array
+ value=(unsigned int *)malloc(sizeof(unsigned int)*columns);
+ //store double values in the integer array by typecasting
+ while(count<columns)
+ {
+ value[count]=(unsigned int)array_ptr[count];
+ count++;
+ }
+ sciprint("\n");
+
+ //ensure that environment is active
+
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ }
+ else {
+ int flag=0;//flag used for finding if the indices to be deleted are valid
+ output=sym_get_num_cols(global_sym_env,&num_cols);//function to find the number of columns in the loaded problem
+ if(output==FUNCTION_TERMINATED_ABNORMALLY)
+ {
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ free(value);//freeing the memory of the allocated pointer
+ return 0;
+ }
+ for(count=0;count<columns;count++)//loop used to check if all the indices mentioned to be deleted are valid
+ {
+ if(value[count]<0 || value[count]>=num_cols){
+ flag=1;
+ break;
+ }
+
+ }
+ if(flag==1)
+ {
+ Scierror(999,"Not valid indices..\n");
+ sciprint("valid indices are from 0 to %d",num_cols-1);
+ free(value);//freeing the memory of the allocated pointer
+ return 0;
+ }
+ //only when the number of columns to be deleted is lesser than the actual number of columns ,execution is proceeded with
+ if(columns<=num_cols){
+ output=sym_delete_cols(global_sym_env,(unsigned int)columns,value);//symphony function to delete the columns specified
+ if(output==FUNCTION_TERMINATED_NORMALLY)
+ {
+ sciprint("Execution is successfull\n");
+ status=0.0;
+ }
+ else if(output==FUNCTION_TERMINATED_ABNORMALLY)
+ {
+ Scierror(999,"Problem occured while deleting the columns,Are the column numbers correct?\n");
+ sciprint("Function terminated abnormally\n");
+ status=1.0;
+ }
+ }
+ else{
+ sciprint("These many number of variables dont exist in the problem\n");
+ status=1.0;
+ }
+
+ }
+
+ int e=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,status);
+ if (e){
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ free(value);//freeing the memory of the allocated pointer
+ return 1;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ free(value);//freeing the memory of the allocated pointer
+ return 0;
+ }
+
+
+//function to remove specified rows
+int sci_sym_delete_rows(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr1,sciErr2;
+ double status=1.0;//assume error status
+ int count=0;//iterator variable
+ int num_rows;//stores the number of columns in the loaded problem
+ int iType= 0;//stores the datatype of matrix
+ int rows=0,columns=0;//integer variables to denote the number of rows and columns in the array denoting the row numbers to be deleted
+ unsigned int *value=NULL;//pointer to integer array allocated dynamically having the indices to be deleted
+ double *array_ptr=NULL;//double array pointer to the array denoting the rows numbers to be deleted
+ int *piAddressVarTwo = NULL;//pointer used to access first and second arguments of the function
+ int output=0;//output parameter for the symphony sym_delete_rows function
+ CheckInputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument as input or not
+ CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument on output side or not
+
+ //load address of 2nd argument into piAddressVarTwo
+ sciErr2=getVarAddressFromPosition(pvApiCtx,1,&piAddressVarTwo);
+
+ if (sciErr2.iErr){
+ printError(&sciErr2, 0);
+ return 0;
+ }
+
+ //check if it is double type
+ sciErr2 = getVarType(pvApiCtx, piAddressVarTwo, &iType);
+ if(sciErr2.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr2, 0);
+ return 0;
+ }
+
+
+ //getting the second argument as a double array
+ sciErr2=getMatrixOfDouble(pvApiCtx,piAddressVarTwo,&rows,&columns,&array_ptr);
+ if (sciErr2.iErr){
+ printError(&sciErr2, 0);
+ return 0;
+ }
+
+ //dynamically allocate the integer array
+ value=(unsigned int *)malloc(sizeof(unsigned int)*columns);
+ //store double values in the integer array by typecasting
+ while(count<columns)
+ {
+ value[count]=(unsigned int)array_ptr[count];
+ count++;
+ }
+ sciprint("\n");
+
+ //ensure that environment is active
+
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ }
+ else {
+ output=sym_get_num_rows(global_sym_env,&num_rows);//function to find the number of rows in the loaded problem
+ if(output==FUNCTION_TERMINATED_ABNORMALLY)
+ {
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ free(value);//freeing the memory of the allocated pointer
+ return 0;
+ }
+ int flag=0;//variable to check if the entered indices are valid.
+ for(count=0;count<columns;count++)//loop used to check if all the indices mentioned to be deleted are valid
+ {
+ if(value[count]<0 || value[count]>=num_rows){
+ flag=1;
+ break;
+ }
+
+ }
+ if(flag==1)
+ {
+ Scierror(999,"Not valid indices..\n");
+ sciprint("valid constraint indices are from 0 to %d",num_rows-1);
+ free(value);//freeing the memory of the allocated pointer
+ return 0;
+ }
+ //only when the number of rows to be deleted is lesser than the actual number of rows ,execution is proceeded with
+ if(columns<=num_rows){
+ output=sym_delete_rows(global_sym_env,(unsigned int)columns,value);//symphony function to delete the rows specified
+ if(output==FUNCTION_TERMINATED_NORMALLY)
+ {
+ sciprint("Execution is successfull\n");
+ status=0.0;
+ }
+ else if(output==FUNCTION_TERMINATED_ABNORMALLY)
+ {
+ Scierror(999,"Problem occured while deleting the columns,Are the column numbers correct?\n");
+ sciprint("Function terminated abnormally\n");
+ status=1.0;
+ }
+ }
+ else{
+ sciprint("These many number of constraints dont exist in the problem\n");
+ status=1.0;
+ }
+
+ }
+
+ int e=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,status);
+ if (e){
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ free(value);//freeing the memory of the allocated pointer
+ return 1;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ free(value);//freeing the memory of the allocated pointer
+ return 0;
+ }
+
+
+
+
+
+}
diff --git a/sci_gateway/cpp/sci_sym_rowmod.cpp b/sci_gateway/cpp/sci_sym_rowmod.cpp
new file mode 100644
index 0000000..ec966d0
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_rowmod.cpp
@@ -0,0 +1,192 @@
+/*
+ * Symphony Toolbox
+ * Functions for modifying constraints
+ * By Keyur Joshi
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+#include <string.h>
+
+int sci_sym_setConstrBound(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ int *varAddress,conIndex,numConstr;
+ double inputDouble,newBound;
+ bool isLower;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,2,2) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //get argument 1: index of constraint whose bound is to be changed
+ if(getUIntFromScilab(1,&conIndex))
+ return 1;
+ iRet=sym_get_num_rows(global_sym_env,&numConstr);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }else if(conIndex>=numConstr){
+ Scierror(999, "An error occured. Constraint index must be a number between 0 and %d.\n",numConstr-1);
+ return 1;
+ }
+
+ //get argument 2: new bound
+ if(getDoubleFromScilab(2,&newBound))
+ return 1;
+
+ //decide which function to execute
+ isLower=(strcmp(fname,"sym_setConstrLower")==0);
+ if(isLower)
+ iRet=sym_set_row_lower(global_sym_env,conIndex,newBound);
+ else
+ iRet=sym_set_row_upper(global_sym_env,conIndex,newBound);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }else{
+ sciprint("Bound successfully changed.\n");
+ }
+
+ //code to give output
+ if(return0toScilab())
+ return 1;
+
+ return 0;
+}
+
+int sci_sym_setConstrType(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ int *varAddress,conIndex,numConstr;
+ double inputDouble,conRHS,conRHS2,conRange;
+ bool isRangedConstr=false;
+ char conType,*conTypeInput;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,3,4) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //get argument 1: index of constraint whose type is to be changed
+ if(getUIntFromScilab(1,&conIndex))
+ return 1;
+ iRet=sym_get_num_rows(global_sym_env,&numConstr);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }else if(conIndex>=numConstr){
+ Scierror(999, "An error occured. Constraint index must be a number between 0 and %d.\n",numConstr-1);
+ return 1;
+ }
+
+ //get argument 2: type of constraint
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isStringType(pvApiCtx,varAddress) )
+ {
+ Scierror(999, "Wrong type for input argument #2: Either \"L\", \"E\", \"G\", or \"R\" is expected.\n");
+ return 1;
+ }
+ iRet = getAllocatedSingleString(pvApiCtx, varAddress, &conTypeInput);
+ if(iRet)
+ {
+ Scierror(999, "Wrong type for input argument #2: Either \"L\", \"E\", \"G\", or \"R\" is expected.\n");
+ return 1;
+ }
+ switch(conTypeInput[0]){
+ case 'l':case 'L':
+ conType='L';
+ break;
+ case 'e':case 'E':
+ conType='E';
+ break;
+ case 'g':case 'G':
+ conType='G';
+ break;
+ case 'r':case 'R':
+ conType='R';
+ isRangedConstr=true;
+ break;
+ default:
+ Scierror(999, "Wrong type for input argument #2: Either \"L\", \"E\", \"G\", or \"R\" is expected.\n");
+ return 1;
+ }
+ //check number of arguments for specific cases
+ if(isRangedConstr){
+ if(nbInputArgument(pvApiCtx)!=4){
+ Scierror(999, "4 Arguments are expected for ranged constraint.\n");
+ return 1;
+ }
+ }else if(nbInputArgument(pvApiCtx)!=3){
+ Scierror(999, "3 Arguments are expected for non-ranged constraint.\n");
+ return 1;
+ }
+
+ //get argument 3: constraint RHS
+ if(getDoubleFromScilab(3,&conRHS))
+ return 1;
+
+ //get argument 4: constraint range
+ if(isRangedConstr){
+ if(getDoubleFromScilab(4,&conRHS2))
+ return 1;
+ //conRHS should be the upper bound, and conRange should be positive
+ if(conRHS>=conRHS2){
+ conRange=conRHS-conRHS2;
+ }else{
+ conRange=conRHS2-conRHS;
+ conRHS=conRHS2;
+ }
+ }else{
+ //if not ranged constraint, just set it to 0, the value probably does not matter anyway
+ conRange=0;
+ }
+
+ iRet=sym_set_row_type(global_sym_env,conIndex,conType,conRHS,conRange);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }else{
+ sciprint("Constraint successfully changed.\n");
+ }
+
+ //code to give output
+ if(return0toScilab())
+ return 1;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_sym_set_indices.cpp b/sci_gateway/cpp/sci_sym_set_indices.cpp
new file mode 100644
index 0000000..6b8a35a
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_set_indices.cpp
@@ -0,0 +1,99 @@
+/*
+ * Implementation Symphony Tool Box for Scilab
+ * sci_sym_set_indices.cpp
+ * contains functions for setting index variables as continuous and integer values
+ * By Iswarya
+ */
+#include <symphony.h>
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env;//defined in globals.cpp
+
+extern "C" {
+#include <api_scilab.h>
+#include <Scierror.h>
+#include <BOOL.h>
+#include <localization.h>
+#include <sciprint.h>
+
+//This function is for setting a index variable to be continuous
+int sci_sym_set_continuous(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr;
+ double status=1.0;//assume error status
+ int index;//to indicate the index of the variable to be set continuous
+ int output=0;//out parameter for the load mps function
+
+ CheckInputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument as input or not
+ CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument on output side or not
+
+ getUIntFromScilab(1,&index);
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ }
+ else
+ {
+ output=sym_set_continuous(global_sym_env,index);//setting the variable continuous
+ if(output==FUNCTION_TERMINATED_ABNORMALLY)
+ {
+ status=1.0;//function did not invoke successfully
+ sciprint("An error occured.\n");
+ }
+ else if(output==FUNCTION_TERMINATED_NORMALLY)
+ {
+ status=0.0;//no error in executing the function
+ sciprint("Variable with index %d is now continuous.\n",index);
+ }
+ }
+
+ if(returnDoubleToScilab(status))
+ return 1;
+
+ return 0;
+}
+
+
+//This function is for setting a index variable to be integer
+int sci_sym_set_integer(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr;
+ double status=1.0;//assume error status
+ int index;//to indicate the index of the variable to be set continuous
+ int output=0;//out parameter for the load mps function
+
+ CheckInputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument as input or not
+ CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument on output side or not
+
+ getUIntFromScilab(1,&index);
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ }
+ else
+ {
+ output=sym_set_integer(global_sym_env,index);//setting the variable continuous
+ if(output==FUNCTION_TERMINATED_ABNORMALLY)
+ {
+ status=1.0;//function did not invoke successfully
+ sciprint("An error occured.\n");
+ }
+ else if(output==FUNCTION_TERMINATED_NORMALLY)
+ {
+ status=0.0;//no error in executing the function
+ sciprint("Variable with index %d is now constrained to be an integer.\n",index);
+ }
+ }
+
+ if(returnDoubleToScilab(status))
+ return 1;
+
+ return 0;
+}
+
+}
+
diff --git a/sci_gateway/cpp/sci_sym_set_variables.cpp b/sci_gateway/cpp/sci_sym_set_variables.cpp
new file mode 100644
index 0000000..327bf84
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_set_variables.cpp
@@ -0,0 +1,430 @@
+/*
+ * Implementation Symphony Tool Box for Scilab
+ * set_variables.cpp
+ * contains function for setting environment variables to their default and userdefined values in symphony
+ * By Iswarya
+ */
+#include <symphony.h>
+
+extern sym_environment* global_sym_env;//defined in globals.cpp
+
+extern "C" {
+#include <api_scilab.h>
+#include <Scierror.h>
+#include <BOOL.h>
+#include <localization.h>
+#include <sciprint.h>
+//This function is for loading a mps file to symphony
+int sci_sym_set_defaults(char *fname, unsigned long fname_len){
+
+ double status=1.0;//assume error status
+ int *piAddressVarOne = NULL;//pointer used to access argument of the function
+ int output=0;//out parameter for the setting of default values function
+ CheckInputArgument(pvApiCtx, 0, 0);//Check we no argument as input or not
+ CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument on output side or not
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ }
+ else {
+ output=sym_set_defaults(global_sym_env);//setting all environment variables and parameters in this symphony environment passed to their default values
+ if(output==FUNCTION_TERMINATED_ABNORMALLY)
+ {
+ status=1.0;//function did not invoke successfully
+ sciprint("Function terminated abnormally, didnot execute");
+ }
+ else if(output==FUNCTION_TERMINATED_NORMALLY)
+ {
+ status=0.0;//no error in executing the function
+ sciprint("Function executed successfully");
+ }
+
+
+ }
+
+ int e=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,status);
+ if (e){
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ return 1;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+
+
+
+int sci_sym_set_int_param(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr1,sciErr2;
+ double status=1.0;//assume error status
+ double num;//to store and check the value obtained is pure unsigned integer
+ int output;//output variable to store the return value of symphony set integer function
+ int value;//to store the value of integer to be set
+ int *piAddressVarOne = NULL;//pointer used to access first argument of the function
+ int *piAddressVarTwo=NULL;//pointer used to access second argument of the function
+ char variable_name[100];//string to hold the name of variable's value to be set
+ char *ptr=variable_name;//pointer to point to address of the variable name
+ CheckInputArgument(pvApiCtx, 2, 2);//Check we have exactly two argument as input or not
+ CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly no argument on output side or not
+
+ //load address of 1st argument into piAddressVarOne
+ sciErr1 = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
+ sciErr2 = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
+ //check whether there is an error or not.
+ if (sciErr1.iErr){
+ printError(&sciErr1, 0);
+ return 0;
+ }
+ if (sciErr2.iErr){
+ printError(&sciErr2, 0);
+ return 0;
+ }
+
+
+ //read the value in that pointer pointing to variable name
+ int err1=getAllocatedSingleString(pvApiCtx, piAddressVarOne, &ptr);
+ //read the value of the variable to be set as a double value
+ int err2=getScalarDouble(pvApiCtx, piAddressVarTwo, &num);
+
+ //check for the integrity of integer value obtained
+ if((double)(unsigned int)num!=(double)num)
+ return 0;
+ else
+ value=(unsigned int)num;//if the value passed is an integer ,store it as an unsigned integer in value variable
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ }
+ else {
+ output=sym_set_int_param(global_sym_env,ptr,value);//symphony function to set the variable name pointed by the ptr pointer to the integer value stored in value variable.
+ if(output==FUNCTION_TERMINATED_NORMALLY){
+ sciprint("setting of integer parameter function executed successfully\n");
+ status=0.0;
+ }
+ else if(output==FUNCTION_TERMINATED_ABNORMALLY){
+ sciprint("setting of integer parameter was unsuccessful.....check your parameter and value\n");
+ status=1.0;
+ }
+ else
+ sciprint("\nerror while executing the setting integer function...check your parameter and value!!\n");
+
+ }
+
+ int e=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,status);
+ if (e){
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ return 1;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+
+
+int sci_sym_get_int_param(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr1;
+ double status=1.0;//assume error status
+ int *piAddressVarOne = NULL;//pointer used to access first argument of the function
+ char variable_name[100];//string to hold the name of variable's value to be retrieved
+ char *ptr=variable_name;//pointer to point to address of the variable name
+ int output;//output parameter for the symphony get_int_param function
+ CheckInputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument as input or not
+ CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument on output side or not
+
+ //load address of 1st argument into piAddressVarOne
+ sciErr1 = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
+
+
+ //check whether there is an error or not.
+ if (sciErr1.iErr){
+ printError(&sciErr1, 0);
+ return 0;
+ }
+
+
+ //read the variable name in that pointer pointing to variable name
+ int err1=getAllocatedSingleString(pvApiCtx, piAddressVarOne, &ptr);
+
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ }
+ else {
+ int a;//local variable to store the value of variable name we want to retrieve
+ output=sym_get_int_param(global_sym_env,ptr,&a);//symphony function to get the value of integer parameter pointed by ptr pointer and store it in 'a' variable
+ if(output==FUNCTION_TERMINATED_NORMALLY){
+ sciprint("value of integer parameter %s is :: %d\n",ptr,a);
+ status=0.0;
+ }
+ else{
+ sciprint("Unable to get the value of the parameter...check the input values!!\n");
+ status=1.0;
+ }
+
+ }
+
+ int e=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,status);
+ if (e){
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ return 1;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+
+
+
+int sci_sym_set_dbl_param(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr1,sciErr2;
+ double status=1.0;//assume error status
+ double num;//to store the value of the double parameter to be set
+ int output;//output parameter for the symphomy setting double parameter function
+ int *piAddressVarOne = NULL;//pointer used to access first argument of the function
+ int *piAddressVarTwo=NULL;//pointer used to access second argument of the function
+ char variable_name[100];//string to hold the name of variable's value to be set
+ char *ptr=variable_name;//pointer to point to address of the variable name
+ CheckInputArgument(pvApiCtx, 2, 2);//Check we have exactly two argument as input or not
+ CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly no argument on output side or not
+
+ //load address of 1st argument into piAddressVarOne
+ sciErr1 = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
+ sciErr2 = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
+ //check whether there is an error or not.
+ if (sciErr1.iErr){
+ printError(&sciErr1, 0);
+ return 0;
+ }
+ if (sciErr2.iErr){
+ printError(&sciErr2, 0);
+ return 0;
+ }
+
+
+ //read the value in that pointer pointing to variable name
+ int err1=getAllocatedSingleString(pvApiCtx, piAddressVarOne, &ptr);
+ //read the value of the variable to be set as a double value
+ int err2=getScalarDouble(pvApiCtx, piAddressVarTwo, &num);
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ }
+ else {
+ output=sym_set_dbl_param(global_sym_env,ptr,num);//symphony function to set the variable name pointed by the ptr pointer to the double value stored in 'value' variable.
+ if(output==FUNCTION_TERMINATED_NORMALLY){
+ sciprint("setting of double parameter function executed successfully\n");
+ status=0.0;
+ }
+ else
+ sciprint("Function did not execute successfully...check your inputs!!!\n");
+
+ }
+
+ int e=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,status);
+ if (e){
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ return 1;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+
+
+int sci_sym_get_dbl_param(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr1;
+ double status=1.0;//assume error status
+ int *piAddressVarOne = NULL;//pointer used to access first argument of the function
+ char variable_name[100];//string to hold the name of variable's value to be retrieved
+ char *ptr=variable_name;//pointer to point to address of the variable name
+ int output;//output parameter for the symphony get_dbl_param function
+ CheckInputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument as input or not
+ CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument on output side or not
+
+ //load address of 1st argument into piAddressVarOne
+ sciErr1 = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
+
+
+ //check whether there is an error or not.
+ if (sciErr1.iErr){
+ printError(&sciErr1, 0);
+ return 0;
+ }
+
+
+ //read the variable name in that pointer pointing to variable name
+ int err1=getAllocatedSingleString(pvApiCtx, piAddressVarOne, &ptr);
+
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ }
+ else {
+ double a;//local variable to store the value of variable name we want to retrieve
+ output=sym_get_dbl_param(global_sym_env,ptr,&a);//symphony function to get the value of double parameter pointed by ptr pointer and store it in 'a' variable
+ if(output==FUNCTION_TERMINATED_NORMALLY){
+ sciprint("value of double parameter %s is :: %lf\n",ptr,a);
+ status=1.0;
+ }
+ else{
+ sciprint("Unable to get the value of the parameter...check the input values!!\n");
+ status=1.0;
+ }
+
+
+ }
+
+ int e=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,status);
+ if (e){
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ return 1;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+
+
+int sci_sym_set_str_param(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr1,sciErr2;
+ double status=1.0;//assume error status
+ double num;//to store the value of the double parameter to be set
+ int output;//output return value of the setting of symphony string parameter function
+ int *piAddressVarOne = NULL;//pointer used to access first argument of the function
+ int *piAddressVarTwo=NULL;//pointer used to access second argument of the function
+ char variable_name[100],value[100];//string to hold the name of variable's value to be set and the value to be set is stored in 'value' string
+ char *ptr=variable_name,*valptr=value;//pointer-'ptr' to point to address of the variable name and 'valptr' points to the address of the value to be set to the string parameter
+ CheckInputArgument(pvApiCtx, 2, 2);//Check we have exactly two argument as input or not
+ CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly no argument on output side or not
+
+ //load address of 1st argument into piAddressVarOne
+ sciErr1 = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
+ sciErr2 = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
+ //check whether there is an error or not.
+ if (sciErr1.iErr){
+ printError(&sciErr1, 0);
+ return 0;
+ }
+ if (sciErr2.iErr){
+ printError(&sciErr2, 0);
+ return 0;
+ }
+
+
+ //read the value in that pointer pointing to variable name
+ int err1=getAllocatedSingleString(pvApiCtx, piAddressVarOne, &ptr);
+ //read the value of the string variable to be set
+ int err2=getAllocatedSingleString(pvApiCtx, piAddressVarTwo, &valptr);
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ }
+ else {
+ output=sym_set_str_param(global_sym_env,ptr,valptr);//symphony function to set the variable name pointed by the ptr pointer to the double value stored in 'value' variable.
+ if(output==FUNCTION_TERMINATED_NORMALLY){
+ sciprint("setting of string parameter function executed successfully\n");
+ status=0.0;
+ }
+ else
+ sciprint("Setting of the string parameter was unsuccessfull...check the input values!!\n");
+
+ }
+
+ int e=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,status);
+ if (e){
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ return 1;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+
+
+int sci_sym_get_str_param(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr1;
+ double status=1.0;//assume error status
+ int *piAddressVarOne = NULL;//pointer used to access first argument of the function
+ char variable_name[100];//string to hold the name of variable's value to be retrieved
+ char *ptr=variable_name;//pointer to point to address of the variable name
+ int output;//output parameter for the symphony get_dbl_param function
+ CheckInputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument as input or not
+ CheckOutputArgument(pvApiCtx, 1, 1);//Check we have exactly one argument on output side or not
+
+ //load address of 1st argument into piAddressVarOne
+ sciErr1 = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
+
+
+ //check whether there is an error or not.
+ if (sciErr1.iErr){
+ printError(&sciErr1, 0);
+ return 0;
+ }
+
+
+ //read the variable name in that pointer pointing to variable name
+ int err1=getAllocatedSingleString(pvApiCtx, piAddressVarOne, &ptr);
+
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ }
+ else {
+ char value[100];//local variable to store the value of variable name we want to retrieve
+ char *p=value;//pointer to store the address of the character array that contains the value of the string parameter to be retrieved
+ output=sym_get_str_param(global_sym_env,ptr,&p);//symphony function to get the value of string parameter pointed by ptr pointer and store it in 'p' pointer variable
+ if(output==FUNCTION_TERMINATED_NORMALLY){
+ sciprint("value of string parameter %s is :: %s\n",ptr,p);
+ status=0.0;
+ }
+ else
+ sciprint("The string parameter value could not be retrieved successfully...check the input values!!\n");
+
+
+ }
+
+ int e=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,status);
+ if (e){
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ return 1;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+
+
+}
diff --git a/sci_gateway/cpp/sci_sym_setcolsoln.cpp b/sci_gateway/cpp/sci_sym_setcolsoln.cpp
new file mode 100644
index 0000000..ca43779
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_setcolsoln.cpp
@@ -0,0 +1,61 @@
+/*
+ * Symphony Toolbox
+ * Function to set the solution to a known one
+ * By Keyur Joshi
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+
+int sci_sym_setColSoln(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ int numVars;
+ double *solution;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,1,1) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //code to process input
+ iRet=sym_get_num_cols(global_sym_env,&numVars);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }
+
+ if(getFixedSizeDoubleMatrixFromScilab(1,1,numVars,&solution))
+ return 1;
+
+ iRet=sym_set_col_solution(global_sym_env,solution);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. The given solution may be infeasible\nor worse than the current solution.\n");
+ return 1;
+ }
+
+ //code to give output
+ if(return0toScilab())
+ return 1;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_sym_setobj.cpp b/sci_gateway/cpp/sci_sym_setobj.cpp
new file mode 100644
index 0000000..3a4691a
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_setobj.cpp
@@ -0,0 +1,126 @@
+/*
+ * Symphony Toolbox
+ * Functions for setting the coefficients of the objective and the sense (minimization/maximization)
+ * By Keyur Joshi
+ */
+
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+
+int sci_sym_setObjCoeff(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ int *varAddress,varIndex,numVars;
+ double inputDouble,newCoeff;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,2,2) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //get argument 1: index of variable whose coefficient is to be changed
+ if(getUIntFromScilab(1,&varIndex))
+ return 1;
+ iRet=sym_get_num_cols(global_sym_env,&numVars);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }else if(varIndex>=numVars){
+ Scierror(999, "An error occured. Variable index must be a number between 0 and %d.\n",numVars-1);
+ return 1;
+ }
+
+ //get argument 2: new coefficient
+ if(getDoubleFromScilab(2,&newCoeff))
+ return 1;
+
+ iRet=sym_set_obj_coeff(global_sym_env,varIndex,newCoeff);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }else{
+ sciprint("Coefficient successfully changed.\n");
+ }
+
+ //code to give output
+ if(return0toScilab())
+ return 1;
+
+ return 0;
+}
+
+int sci_sym_setObjSense(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ int *varAddress;
+ double objSense;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,1,1) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //code to process input
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &varAddress);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ if ( !isDoubleType(pvApiCtx,varAddress) || isVarComplex(pvApiCtx,varAddress) )
+ {
+ Scierror(999, "Wrong type for input argument #1:\nEither 1 (sym_minimize) or -1 (sym_maximize) is expected.\n");
+ return 1;
+ }
+ iRet = getScalarDouble(pvApiCtx, varAddress, &objSense);
+ if(iRet || (objSense!=-1 && objSense!=1))
+ {
+ Scierror(999, "Wrong type for input argument #1:\nEither 1 (sym_minimize) or -1 (sym_maximize) is expected.\n");
+ return 1;
+ }
+ iRet=sym_set_obj_sense(global_sym_env,objSense);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured.\n");
+ return 1;
+ }else{
+ if(objSense==1)
+ sciprint("The solver has been set to minimize the objective.\n");
+ else
+ sciprint("The solver has been set to maximize the objective.\n");
+ }
+
+ //code to give output
+ if(return0toScilab())
+ return 1;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_sym_solution.cpp b/sci_gateway/cpp/sci_sym_solution.cpp
new file mode 100644
index 0000000..a08e5b9
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_solution.cpp
@@ -0,0 +1,101 @@
+/*
+ * Symphony Toolbox
+ * Provides the solution after the problem is solved
+ * By Keyur Joshi
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+
+int sci_sym_getVarSoln(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ int numVars;
+ double *solution;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,0,0) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //code to process input
+ iRet=sym_get_num_cols(global_sym_env,&numVars);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has the problem been loaded and solved?\n");
+ return 1;
+ }
+ solution=new double[numVars];
+ iRet=sym_get_col_solution(global_sym_env,solution);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ //Scierror(999, "An error occured. Has the problem been solved? Is the problem feasible?\n");
+ delete[] solution;
+ return 1;
+ }
+
+ //code to give output
+ sciErr=createMatrixOfDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,1,numVars,solution);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ delete[] solution;
+ return 1;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ ReturnArguments(pvApiCtx);
+
+ delete[] solution;
+
+ return 0;
+}
+
+int sci_sym_getObjVal(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ double solution;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,0,0) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //code to process input
+ iRet=sym_get_obj_val(global_sym_env,&solution);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has the problem been loaded and solved? Is the problem feasible?\n");
+ return 1;
+ }
+
+ //code to give output
+ if(returnDoubleToScilab(solution))
+ return 1;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_sym_solve.cpp b/sci_gateway/cpp/sci_sym_solve.cpp
new file mode 100644
index 0000000..4abb268
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_solve.cpp
@@ -0,0 +1,49 @@
+/*
+ * Implementation Symphony Tool Box for Scilab
+ * Contains sym_solve function
+ * Author : Sai Kiran
+ */
+
+#include <symphony.h>
+#include <sci_iofunc.hpp>
+extern sym_environment* global_sym_env;//defined in globals.cpp
+
+extern "C" {
+#include <api_scilab.h>
+#include <Scierror.h>
+#include <BOOL.h>
+#include <localization.h>
+#include <sciprint.h>
+#include <stdio.h>
+int process_ret_val(int);
+
+int sci_sym_solve(char *fname, unsigned long fname_len){
+
+ int status=0;
+
+ //check whether we have no input and one output argument or not
+ CheckInputArgument(pvApiCtx, 0, 0) ;//no input argument
+ CheckOutputArgument(pvApiCtx, 1, 1) ;//one output argument
+
+ // Check environment
+ if(global_sym_env==NULL)
+ sciprint("Error: Symphony environment is not initialized.\n");
+ else {// There is an environment opened
+ double time_limit = -1.0;
+ status = sym_get_dbl_param(global_sym_env,"time_limit",&time_limit);
+
+ if (status == FUNCTION_TERMINATED_NORMALLY) {
+ if ( time_limit < 0.0 )
+ sciprint("\nNote: There is no limit on time.\n");
+ else sciprint("\nNote: Time limit has been set to %lf.\n",time_limit);
+ status=process_ret_val(sym_solve(global_sym_env));// Call function
+ }
+ else {
+ sciprint("\nUnable to read time limit.\n");
+ status = 1; //Error state
+ }
+ }
+ // Return result to scilab
+ return returnDoubleToScilab(status);
+ }
+}
diff --git a/sci_gateway/cpp/sci_sym_varbounds.cpp b/sci_gateway/cpp/sci_sym_varbounds.cpp
new file mode 100644
index 0000000..e0fa6ab
--- /dev/null
+++ b/sci_gateway/cpp/sci_sym_varbounds.cpp
@@ -0,0 +1,76 @@
+/*
+ * Symphony Toolbox
+ * Functions for setting the upper and lower bounds of the variables
+ * By Keyur Joshi
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+#include <string.h>
+
+int sci_sym_setVarBound(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+ int *varAddress,varIndex,numVars;
+ double inputDouble,newBound;
+ bool isLower;
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx,2,2) ;
+ CheckOutputArgument(pvApiCtx,1,1) ;
+
+ //get argument 1: index of variable whose bound is to be changed
+ if(getUIntFromScilab(1,&varIndex))
+ return 1;
+ iRet=sym_get_num_cols(global_sym_env,&numVars);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }else if(varIndex>=numVars){
+ Scierror(999, "An error occured. Variable index must be a number between 0 and %d.\n",numVars-1);
+ return 1;
+ }
+
+ //get argument 2: new bound
+ if(getDoubleFromScilab(2,&newBound))
+ return 1;
+
+ //decide which function to execute
+ isLower=(strcmp(fname,"sym_setVarLower")==0);
+ if(isLower)
+ iRet=sym_set_col_lower(global_sym_env,varIndex,newBound);
+ else
+ iRet=sym_set_col_upper(global_sym_env,varIndex,newBound);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }else{
+ sciprint("Bound successfully changed.\n");
+ }
+
+ //code to give output
+ if(return0toScilab())
+ return 1;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sci_vartype.cpp b/sci_gateway/cpp/sci_vartype.cpp
new file mode 100644
index 0000000..e6656a7
--- /dev/null
+++ b/sci_gateway/cpp/sci_vartype.cpp
@@ -0,0 +1,135 @@
+/*
+ * Symphony Toolbox
+ * Provides information about variables: is it continuous/integer/boolean?
+ * By Keyur Joshi
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+
+//error management variable
+static SciErr sciErr;
+static int iRet;
+
+//data declarations
+static int *varAddress,varIndex,numVars,retVal;
+static double inputDouble;
+
+static int checkNumArgs()
+{
+ CheckInputArgument(pvApiCtx,1,1);
+ CheckOutputArgument(pvApiCtx,1,1);
+ return 1;
+}
+
+static int commonCodePart1(){
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ if(checkNumArgs()==0)
+ return 1;
+
+ //code to process input
+ if(getUIntFromScilab(1,&varIndex))
+ return 1;
+ iRet=sym_get_num_cols(global_sym_env,&numVars);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }else if(varIndex>=numVars){
+ Scierror(999, "An error occured. Variable index must be a number between 0 and %d.\n",numVars-1);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int commonCodePart2(){
+ if(returnDoubleToScilab(retVal))
+ return 1;
+
+ return 0;
+}
+
+int sci_sym_isContinuous(char *fname){
+
+ if(commonCodePart1())
+ return 1;
+
+ iRet=sym_is_continuous(global_sym_env,varIndex,&retVal);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured. Has a problem been loaded?\n");
+ return 1;
+ }else{
+ if(retVal)
+ sciprint("This variable is continuous.\n");
+ else
+ sciprint("This variable is not continuous.\n");
+ }
+
+ if(commonCodePart2())
+ return 1;
+
+ return 0;
+}
+
+int sci_sym_isBinary(char *fname){
+
+ if(commonCodePart1())
+ return 1;
+
+ iRet=sym_is_binary(global_sym_env,varIndex,&retVal);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured.\n");
+ return 1;
+ }else{
+ if(retVal)
+ sciprint("This variable is constrained to be binary.\n");
+ else
+ sciprint("This variable is not constrained to be binary.\n");
+ }
+
+ if(commonCodePart2())
+ return 1;
+
+ return 0;
+}
+
+int sci_sym_isInteger(char *fname){
+
+ char retValc; //for some wierd reason this function unlike the above 2 returns a char
+
+ if(commonCodePart1())
+ return 1;
+
+ iRet=sym_is_integer(global_sym_env,varIndex,&retValc);
+ if(iRet==FUNCTION_TERMINATED_ABNORMALLY){
+ Scierror(999, "An error occured.\n");
+ return 1;
+ }else{
+ if(retValc)
+ sciprint("This variable is constrained to be an integer.\n");
+ else
+ sciprint("This variable is not constrained to be an integer.\n");
+ }
+ retVal=retValc;
+
+ if(commonCodePart2())
+ return 1;
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/cpp/sym_data_query_functions.cpp b/sci_gateway/cpp/sym_data_query_functions.cpp
new file mode 100644
index 0000000..b0d0989
--- /dev/null
+++ b/sci_gateway/cpp/sym_data_query_functions.cpp
@@ -0,0 +1,404 @@
+/*
+ * Implementation Symphony Tool Box for Scilab
+ * sym_data_query_functions.cpp
+ * contains Data Query Functions( 13 functions)
+ * Author: Sai Kiran
+ */
+
+#include <symphony.h>
+#include <sci_iofunc.hpp>
+extern sym_environment* global_sym_env;//defined in globals.cpp
+
+extern "C" {
+#include <api_scilab.h>
+#include <Scierror.h>
+#include <BOOL.h>
+#include <localization.h>
+#include <sciprint.h>
+
+#include <string.h>
+
+// Function to print termination status of a function
+void show_termination_status(int status) {
+ if (status == FUNCTION_TERMINATED_ABNORMALLY)
+ sciprint("\nFunction invoked unsuccessfully.\n");
+ //else
+ //sciprint("\nFunction invoked successfully.\n");
+ }
+
+/*
+ * Generelized function for sym_getNumVars,
+ * sym_getNumConstrs,sym_get_NumElements
+*/
+int sci_sym_get_num_int(char *fname, unsigned long fname_len){
+
+ int result=-1;/* Result of the callar */
+
+ //check whether we have no input and one output argument or not
+ CheckInputArgument(pvApiCtx, 0, 0) ; //no input argument
+ CheckOutputArgument(pvApiCtx, 1, 1) ; //one output argument
+
+ /* Array of possible callers of this function */
+ char* arr_caller[]={"sym_getNumConstr","sym_getNumVar","sym_getNumElements"};
+
+ /* Array of functions to be called */
+ int (*fun[])(sym_environment*,int*)= { sym_get_num_rows,
+ sym_get_num_cols,
+ sym_get_num_elements
+ };
+
+ if(global_sym_env==NULL) //There is no environment opened.
+ sciprint("Error: Symphony environment is not initialized.\n");
+ else {
+ //There is an environment opened
+ int iter=0,length=sizeof(arr_caller)/sizeof(char*),found_at= -1;
+ for (;iter < length ;++iter){
+ if (!strcmp(fname,arr_caller[iter]))
+ found_at=iter;
+ }
+ if (found_at != -1) {
+ int ret_val=fun[found_at](global_sym_env,&result);
+ show_termination_status(ret_val);
+ if (ret_val == FUNCTION_TERMINATED_ABNORMALLY)
+ result=-1;
+ }
+ else //very rare case
+ sciprint("\nError in function mapping in scilab script\n");
+ }
+
+ //Copy the result to scilab. Location is position next to input arguments.
+ return returnDoubleToScilab(result);
+ }
+
+/* This is generelized function for
+ * sym_getVarLower,sym_getVarUpper,sym_getRhs,sym_getConstrRange,sym_getConstrLower,
+ * sym_getConstrUpper and sym_getObjCoeff .
+ * (Functions taking symphony env and pointer to array of doubles as arguments)
+*/
+int sci_sym_get_dbl_arr(char *fname, unsigned long fname_len){
+
+ int result_len=0;/* Length of the output double array */
+ double *result=NULL;/* Pointer to output double array */
+
+ //check whether we have no input and one output argument or not
+ CheckInputArgument(pvApiCtx, 0, 0) ; //no input argument
+ CheckOutputArgument(pvApiCtx, 1, 1) ; //one output argument
+
+ /* Array of possible callers of this function */
+ char* arr_caller[]={"sym_getVarLower","sym_getVarUpper",
+ "sym_getRhs","sym_getConstrRange",
+ "sym_getConstrLower","sym_getConstrUpper",
+ "sym_getObjCoeff"};
+
+ /* Array of functions to be called */
+ int (*fun[])(sym_environment*,double*)= {sym_get_col_lower,sym_get_col_upper,
+ sym_get_rhs,sym_get_row_range,
+ sym_get_row_lower,sym_get_row_upper,
+ sym_get_obj_coeff };
+
+ /* Array of functions the above functions depend on */
+ int (*fun_depends[])(sym_environment*,int*) = {sym_get_num_cols,sym_get_num_cols,
+ sym_get_num_rows,sym_get_num_rows,
+ sym_get_num_rows,sym_get_num_rows,
+ sym_get_num_cols };
+
+ /* We want to ouput row-matrix if we are dealing with column data .
+ * column matrix if we are dealing with row data .
+ * 0 - output a row matrix.
+ * 1 - output a column matrix.
+ */
+ int representation = 0; //output a row matrix
+
+ /* Array of representations of output depending on the above functions.
+ * It's length is same as above arrays.
+ */
+ int matrix_representation[] = { 0 ,0 , 1, 1, 1, 1, 0};
+ if(global_sym_env==NULL) //There is no environment opened.
+ sciprint("Error: Symphony environment is not initialized.\n");
+ else {
+ //There is an environment opened
+ int iter=0,length=sizeof(arr_caller)/sizeof(char*),found_at= -1;
+ for (;iter < length ;++iter){
+ if (!strcmp(fname,arr_caller[iter]))
+ found_at=iter;
+ }
+ if (found_at != -1){
+ int status1=fun_depends[found_at](global_sym_env,&result_len);
+ if ( status1 == FUNCTION_TERMINATED_NORMALLY && result_len ) {
+ result=(double*)malloc( sizeof(double) * result_len );
+ int ret_val=fun[found_at](global_sym_env,result);
+ show_termination_status(ret_val);
+ if (ret_val == FUNCTION_TERMINATED_ABNORMALLY)
+ result_len=0;
+ else {
+ if (found_at == 6) {//if called function is sym_getObjCoeff
+ int iter=0,sense=0,status2 = sym_get_obj_sense(global_sym_env,&sense);
+ if (sense == -1) // Multiply with -1 while showing
+ for (;iter < result_len;++iter) result[iter] *= -1;
+ }
+ representation = matrix_representation[found_at];
+ }
+ }
+ else
+ sciprint("\n Is a problem loaded ? \n");
+ }
+ else //very rare case
+ sciprint("\nError in function mapping in scilab script\n");
+ }
+
+ //Copy the result to scilab. Location is position next to input arguments.
+ SciErr err;
+ if (representation) // output a column-matrix
+ err=createMatrixOfDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,result_len,1,result);
+ else // output a row-matrix
+ err=createMatrixOfDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,1,result_len,result);
+ free(result); //Free the allocated space
+ result=NULL; //Set to NULL
+ if (err.iErr){ //Process error
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ printError(&err, 0);
+ return 1;
+ }
+
+ //assign result position to output argument
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+/* This function returns rows sense of the problem loaded
+*/
+int sci_sym_get_row_sense(char *fname, unsigned long fname_len) {
+
+ //check whether we have no input and one output argument or not
+ CheckInputArgument(pvApiCtx, 0, 0) ; //no input argument
+ CheckOutputArgument(pvApiCtx, 1, 1) ; //one output argument
+
+ // Create a dummy string
+ char *dummy=(char*)malloc(sizeof(char));
+ char **correct=NULL; // Correct result of the function
+ dummy[0]='\0';
+ char **row_senses=&dummy;
+ int num_rows=0;
+ if(global_sym_env==NULL) //There is no environment opened.
+ sciprint("Error: Symphony environment is not initialized.\n");
+ else {
+ int status=sym_get_num_rows(global_sym_env,&num_rows);
+ if (status != FUNCTION_TERMINATED_ABNORMALLY) { //If function terminated normally
+ char senses[num_rows];
+ char *ptr=senses;
+ // Take rows sense from symphony
+ int status1=sym_get_row_sense(global_sym_env,ptr);
+ if (status1 == FUNCTION_TERMINATED_ABNORMALLY) {
+ sciprint("\n Is a problem loaded ? \n");
+ show_termination_status(status1);
+ row_senses=&dummy;
+ num_rows=0;
+ }
+ else { // If function terminated normally
+ // Convert every character to string
+ correct=(char**)malloc(sizeof(char*) * num_rows);
+ int iter=0;
+ for (;iter < num_rows;++iter) {
+ correct[iter]=(char*)malloc(sizeof(char)*2);
+ correct[iter][0]=senses[iter];
+ correct[iter][1]='\0';
+ }
+ row_senses=correct;
+ show_termination_status(status1);// Show termination status of caller
+ }
+ }
+ else show_termination_status(status);
+ }
+ // Write output to scilab memory
+ SciErr err=createMatrixOfString(pvApiCtx,nbInputArgument(pvApiCtx)+1,num_rows,1,row_senses);
+ free(dummy); //free dummy variable
+ dummy=NULL;
+ if (correct){ // If we have allocated
+ int iter=0;
+ for (;iter < num_rows;++iter){
+ free(correct[iter]); // Free each element in it
+ }
+ free(correct); // Free it
+ correct=NULL;
+ }
+ if (err.iErr){ //Process error
+ printError(&err, 0);
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ return 0;
+ }
+
+ //assign result position to output argument
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+/*
+ * Proto-type of function that converts column-major (sparse) representation
+ * to row-major (sparse) representation .
+*/
+void column_major_to_row_major(int,int,int,double *,int *,int *,double *,int *,int *);
+
+
+/* This function is to retrieve the problem's constraint matrix (sparse) .
+ * Symphony uses column-major (sparse) representation.
+ * Scilab uses row-major (sparse) representation.
+ * So, This function takes column-major (sparse) representation from symphony ,
+ * converts that to row-major (sparse) representation and writes to scilab's memory.
+ *
+ **/
+int sci_sym_get_matrix(char *fname, unsigned long fname_len){
+ int nz_ele=0;// No.of non-zero elements of the matrix
+ int rows=0; //No. of rows in constraint matrix
+ int columns=0; //No. of columns in constraint matrix
+
+ /* Variables that store column-major representation of matrix.
+ * These variables will be filled by symphony
+ */
+ int *column_start=NULL;// Starting index(in elements array) of each column
+ int *row_indices=NULL;// Row indices corresponding to each non-zero element
+ double *elements=NULL;// Non-zero elements of matrix
+
+ /* Variables that store row-major representation of matrix.
+ * Filled by a function column_major_to_row_major.
+ */
+ double *new_list=NULL; // Non-zero elements of row-major representation
+ int *count_per_row=NULL; //Count of non-zero elements in earch row
+ int *column_position=NULL; //Column of each non-zero element
+
+ //check whether we have no input and one output argument or not
+ CheckInputArgument(pvApiCtx, 0, 0) ; //no input argument
+ CheckOutputArgument(pvApiCtx, 1, 1) ; //one output argument
+
+ if(global_sym_env==NULL) //There is no environment opened.
+ sciprint("Error: Symphony environment is not initialized.\n");
+ else { //There is an environment opened
+ int status1=sym_get_num_elements(global_sym_env,&nz_ele); //No. of non-zero elements
+ int status2=sym_get_num_cols(global_sym_env , &columns); //Columns
+ int status3=sym_get_num_rows(global_sym_env , &rows); //Rows
+ int status4=FUNCTION_TERMINATED_ABNORMALLY;
+
+ //Make sure functions terminated normally
+ if (status1 == status2 && status1 == status3 && status1 == FUNCTION_TERMINATED_NORMALLY){
+ //Allocate memory for column-major representation
+ column_start=(int*)malloc(sizeof(int) * (columns+1));
+ row_indices=(int*)malloc(sizeof(int) * nz_ele);
+ elements=(double*)malloc(sizeof(double) * nz_ele);
+
+ //Take column-major representation from symphony
+ status4=sym_get_matrix(global_sym_env,&nz_ele,column_start,row_indices,elements);
+ if (status1 == status4) { //Check termination status of function, if normal
+ //Show status of caller as normal termination
+ show_termination_status(FUNCTION_TERMINATED_NORMALLY);
+
+ //Allocate memory for row-major representation
+ new_list=(double*) calloc( nz_ele , sizeof(double));
+ count_per_row=(int*) calloc( rows, sizeof(int ) );
+ column_position=(int*) calloc( nz_ele, sizeof(int));
+
+ //Convert column-major representation to row-major representation
+ column_major_to_row_major(rows,columns,nz_ele,elements,row_indices,column_start,new_list,count_per_row,column_position);
+
+ /*
+ (Important)Scilab considers indices from 1 , But we have column indices starting from 0 in column_position.
+ Hence add 1 to each index
+ */
+ int iter=0;
+ for (;iter < nz_ele ; ++iter) column_position[iter]++;
+
+ }
+ else { //If termination status is abnormal
+ show_termination_status(FUNCTION_TERMINATED_ABNORMALLY);
+ sciprint("\n Is a problem loaded ? \n");
+ }
+ }
+ else //If termination status of any of functions is abnormal
+ show_termination_status(FUNCTION_TERMINATED_ABNORMALLY);
+
+ }
+
+ //Copy the result to scilab. Location is position next to input arguments.
+ SciErr err=createSparseMatrix(pvApiCtx,nbInputArgument(pvApiCtx)+1,rows,columns,nz_ele,count_per_row,column_position,new_list);
+
+ /*
+ *Free allocated memory before exit
+ */
+ free(row_indices);
+ free(column_start);
+ free(elements);
+ free(new_list);
+ free(count_per_row);
+ free(column_position);
+
+ if (err.iErr){ //Process error
+ printError(&err, 0);
+ AssignOutputVariable(pvApiCtx, 1) = 0;
+ return 1;
+ }
+
+ //assign result position to output argument
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+/*
+ * It converts column-major representation to row-major representation
+ * :: ARGUMENTS ::
+ * rows - No. of rows IN
+ * columns - No. of columns IN
+ * nz_ele - No. of non-zero elements IN
+ * elements - Non-zero elements in column-major representation IN
+ * row_indices - Row index( starts from 0 : symphony) of each non-zero element IN
+ * column_start - Starting index in elements of each column IN
+ * new_list - Non-zero elements in row-major representation OUT
+ * count_per_row - Count of non-zero elements in each row OUT
+ * column_position - Column index ( starts from 0 (we'll add 1 to each index later)) of each non-zero element OUT
+*/
+void column_major_to_row_major(int rows,int columns,int nz_ele,double *elements,int *row_indices,int *column_start,double *new_list,int *count_per_row,int *column_position) {
+
+ int iter=0,iter2,iter3=0,index=0;
+ for (iter=0;iter < rows;++iter) {
+ for (iter2=0;iter2 < nz_ele;++iter2) {
+ if (row_indices[iter2] == iter) {
+ count_per_row[iter]++; //Count of non-zero elements per row.
+ new_list[index]=elements[iter2];
+ for (iter3=0; iter3 < columns+1 ; ++iter3) {
+ if (iter2 < column_start[iter3])
+ break;
+ }
+ column_position[index] = iter3 - 1;
+ index++ ;
+ }
+ }
+ }
+ }
+
+
+/*
+ * This function is used to get iteration count after solving a problem
+*/
+int sci_sym_get_iteration_count(char *fname, unsigned long fname_len){
+
+ //check whether we have no input and one output argument or not
+ CheckInputArgument(pvApiCtx, 0, 0) ; //no input argument
+ CheckOutputArgument(pvApiCtx, 1, 1) ; //one output argument
+
+ int iteration_count=0; // return value to the caller
+ if(global_sym_env==NULL) //There is no environment opened.
+ sciprint("Error: Symphony environment is not initialized.\n");
+ else { //There is an environment opened
+ //Call symphony function
+ int status=sym_get_iteration_count(global_sym_env,&iteration_count);
+ show_termination_status(status);
+ if (status == FUNCTION_TERMINATED_ABNORMALLY) {
+ sciprint("\nHave you solved a problem ?\n");
+ iteration_count = 0;
+ }
+ }
+ // Write the result to scilab
+ return returnDoubleToScilab(iteration_count);
+ }
+
+}
diff --git a/sci_gateway/cpp/template.cpp b/sci_gateway/cpp/template.cpp
new file mode 100644
index 0000000..a835fc3
--- /dev/null
+++ b/sci_gateway/cpp/template.cpp
@@ -0,0 +1,43 @@
+/*
+ * Symphony Toolbox
+ * <Description>
+ * <Author(s)>
+ */
+#include "symphony.h"
+#include "sci_iofunc.hpp"
+
+extern sym_environment* global_sym_env; //defined in globals.cpp
+
+extern "C" {
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "sciprint.h"
+#include "BOOL.h"
+#include <localization.h>
+
+int sci_template(char *fname){
+
+ //error management variable
+ SciErr sciErr;
+ int iRet;
+
+ //data declarations
+
+ //ensure that environment is active
+ if(global_sym_env==NULL){
+ sciprint("Error: Symphony environment not initialized. Please run 'sym_open()' first.\n");
+ return 1;
+ }
+
+ //code to check arguments and get them
+ CheckInputArgument(pvApiCtx, , ) ;
+ CheckOutputArgument(pvApiCtx, , ) ;
+
+ //code to process input
+
+ //code to give output
+
+ return 0;
+}
+
+}
diff --git a/sci_gateway/loader_gateway.sce b/sci_gateway/loader_gateway.sce
new file mode 100644
index 0000000..6809d99
--- /dev/null
+++ b/sci_gateway/loader_gateway.sce
@@ -0,0 +1,24 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder_gateway.sce: Please, do not edit this file
+
+try
+ v = getversion("scilab");
+catch
+ v = [ 5 0 ]; // or older
+end
+if (v(1) <= 5) & (v(2) < 3) then
+ // new API in scilab 5.3
+ error(gettext("Scilab 5.3 or more is required."));
+end
+
+sci_gateway_dir = get_absolute_file_path("loader_gateway.sce");
+current_dir = pwd();
+
+chdir(sci_gateway_dir);
+if ( isdir("cpp") ) then
+ chdir("cpp");
+ exec("loader.sce");
+end
+
+chdir(current_dir);
+clear sci_gateway_dir current_dir v;