int Params_InitType(PyObject *module) { int retval, i, existing_count=0, new_count=0; // Count the existing get-seters, and how many new ones we need. PyGetSetDef *gsdef = ParamsType.tp_getset; if (gsdef) { for (existing_count = 0; gsdef[existing_count].name; existing_count++); } for (new_count = 0; Params_pgs[new_count].attr_name; new_count++); // We need as many get setters as these combined, plus a null terminator. gsdef = (PyGetSetDef*)calloc(new_count+existing_count+1,sizeof(PyGetSetDef)); gsdef[new_count+existing_count] = ParamsType.tp_getset[existing_count]; // Copy over all existing non-trivial entries... for (i=0; i<existing_count; ++i) gsdef[i] = ParamsType.tp_getset[i]; // Define the new entries. for (i=0; i<new_count; ++i) { struct param_getsets *pgs = Params_pgs+i; PyGetSetDef gs = {pgs->attr_name, (getter)Params_parameter_get, (setter) (pgs->readonly ? NULL : Params_parameter_set), pgs->doc, (void*)pgs }; gsdef[existing_count+i] = gs; } // Finally, set it up... ParamsType.tp_getset = gsdef; retval=util_add_type(module, &ParamsType); //free(gsdef); // Why the f**k would Python want to keep *this* around?!! return retval; }
int Bar_InitType(PyObject *module) { int retval; if ((retval=util_add_type(module, &BarType))!=0) return retval; // These are used in setting the stat return 0; }
int LPX_InitType(PyObject *module) { int retval; if ((retval=util_add_type(module, &LPXType))!=0) return retval; // Add in constant flag terms used in this class. // The following macro helps set constants. #define SETCONST(A) PyDict_SetIntString(LPXType.tp_dict, #A, GLP_ ## A) #if GLPK_VERSION(4, 31) // These are used in the LPX.scale method. SETCONST(SF_GM); SETCONST(SF_EQ); SETCONST(SF_2N); SETCONST(SF_SKIP); SETCONST(SF_AUTO); #endif // These are used in control parameters for solvers. SETCONST(MSG_OFF); SETCONST(MSG_ERR); SETCONST(MSG_ON); SETCONST(MSG_ALL); SETCONST(PRIMAL); #if GLPK_VERSION(4, 31) SETCONST(DUAL); #endif SETCONST(DUALP); SETCONST(PT_STD); SETCONST(PT_PSE); SETCONST(RT_STD); SETCONST(RT_HAR); #if GLPK_VERSION(4, 20) SETCONST(BR_FFV); SETCONST(BR_LFV); SETCONST(BR_MFV); SETCONST(BR_DTH); SETCONST(BT_DFS); SETCONST(BT_BFS); SETCONST(BT_BLB); SETCONST(BT_BPH); #endif #if GLPK_VERSION(4, 21) SETCONST(PP_NONE); SETCONST(PP_ROOT); SETCONST(PP_ALL); #endif #undef SETCONST // Add in the calls to the other objects. if ((retval=Obj_InitType(module))!=0) return retval; #ifdef USEPARAMS if ((retval=Params_InitType(module))!=0) return retval; #endif if ((retval=BarCol_InitType(module))!=0) return retval; if ((retval=KKT_InitType(module))!=0) return retval; #if GLPK_VERSION(4, 20) if ((retval=Tree_InitType(module))!=0) return retval; #endif return 0; }
int KKT_InitType(PyObject *module) { return util_add_type(module, &KKTType); }