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 main(int argc, char **argv) { #if USE_VRPH // A few things required by VRPH int i; double best_sol=VRP_INFINITY; int best_sol_buff[500]; #endif vrp_problem *vrp; sym_environment *env = sym_open_environment(); version(); sym_parse_command_line(env, argc, argv); sym_get_user_data(env, (void**)&vrp); #if USE_VRPH // Get the size of the problem in the input file int n=VRPGetDimension(vrp->par.infile); // Declare a VRP object of size n VRP V(n); // Declare a ClarkeWright object of size n ClarkeWright CW(n); // Populate the VRP object with the input file V.read_TSPLIB_file(vrp->par.infile); // Now create NUM_VRPH_SOLUTIONS solutions using VRPH and set the // upper bound to the best solution discovered for(i=0;i<NUM_VRPH_SOLUTIONS;i++) { // Create default routes - each customer on its own route V.create_default_routes(); // Create a new random feasible solution with Clarke Wright CW.Construct(&V, .5+ lcgrand(1),false); // Improve it with the RTR heuristic V.RTR_solve(ONE_POINT_MOVE+TWO_POINT_MOVE+TWO_OPT+THREE_OPT, 30,5,1,.01,25,VRPH_LI_PERTURB,VRPH_BEST_ACCEPT,false); if(V.get_total_route_length()-V.get_total_service_time()<best_sol) { best_sol=V.get_total_route_length()-V.get_total_service_time(); V.export_canonical_solution_buff(best_sol_buff); } // Reset VRPH's internal data structures V.reset(); } // Import the best solution and display it - if SYMPHONY claims an infeasibility // because the VRPH solution is optimal, we wouldn't see it otherwise! printf("VRPH set SYMPHONY upper bound to %f based on solution:\n",best_sol); V.import_solution_buff(best_sol_buff); V.summary(); // Set the upper bound using VRPH solution by accessing SYMPHONY's // internal data structures env->has_ub=1; env->ub=best_sol ; #if 0 // Note that this might be incorrect if the VRPH solution is not optimal // So the # of trucks still needs to be passed in on the command line! vrp->numroutes=V.get_total_number_of_routes(); #endif #endif // Now just let SYMPHONY do its thing. If an infeasibility is encountered, // then this certifies that the solution found by VRPH is indeed optimal // Note that the par.test will not work as we have processed only a single // file. Thus, we changed the following line // if (vrp->par.test){ if (0 && vrp->par.test){ vrp_test(env, argc, argv); } else { sym_load_problem(env); sym_find_initial_bounds(env); sym_set_str_param(env, "lp_executable_name", "vrp_lp_cg"); sym_set_str_param(env, "cp_executable_name", "vrp_cp"); sym_set_int_param(env, "generate_cgl_cuts", FALSE); sym_solve(env); } sym_close_environment(env); return(0); }