User:Franc
Franc Ivankovic is (Dec-Jan 2010) working on adding support for the ABsolver solver to ASCEND.
- absolver:solvers/absolver
- absolver:ascend/compiler/logrel_cnf.c
- absolver:ascend/compiler/logrel_cnf.h
Notes from John about parse WHEN lists
The 'relation_term' data structures:
ascend/compiler/relation_type.h
Sample code that manipulates same:
ascend/compiler/exprsym.h
How to get access to the list of whens...
Note we looked at CMSlv and we found that instead of accessing the list of WHENs directly, the solver was instead parsing the 'dvars' or discrete variables and identifying which WHEN each of those variables occurred it. For reasons that benefited the algorithm that they wanted to implement.
We have a different need, which is to export the whole model to another solver.
cd ~/ascend/ascend cscope -qR
ascend/system/slv_client.h
slv_get_solvers_when_list(...)
Returns a NULL-terminated list.
ascend/system/conditional.h
extern struct gl_list_t *when_dvars_list( struct w_when *when); /**< Retrieves the list of dis variables of the given when. */
extern struct gl_list_t *when_cases_list( struct w_when *when); /**< Retrieves the list of cases of the given when. */
Note that the above functions return 'gl_list_t' objects, for which you need to use the routines in
ascend/general/list.h
like gl_fetch and gl_length, for example, in looping. Note that gl_lists start at 1 and not 0 like most C arrays. Stoopid.
extern int32 *when_case_values_list( struct when_case *wc); /**< Retrieves the list of values of the given case. */
will tell us the values of the dvars in the present 'when_case'.
extern struct gl_list_t *when_case_rels_list( struct when_case *wc); /**< Retrieves the list of rels of the given case. */
will tell us the relations that are switched on by this case.
but not that WHENs can also be used to switch on...
...logical relations...
extern struct gl_list_t *when_case_logrels_list( struct when_case *wc); /**< Retrieves the list of logrels of the given case. */
...and nested WHENs...
extern struct gl_list_t *when_case_whens_list( struct when_case *wc); /**< Retrieves the list of whens nested in the given case. */
That looks like all you need to know... I hope. You might have to
double-check the types of the objects being returned in the above.
Note that 'var_variable' and 'rel_relation' have names that are generated by the compiler, and with a bit of fiddling, they are accessible to the solver. You might find some code to help with that tucked away in some of the other solvers.
var_make_name or something like...
Names can include dots, etc
mymodel.submodel.var1
To build up the tree, you will need to have some tree-data-structure functions. The ones in exprsym.c are good examples, but not all that you need.
static Term *MakeAdd(Term *left, Term *right)
for example does the job of creating a "plus" node that is linked to left and right operands.
The advantage of using these built-in data structures is that you can probably test your to-CNF routines without having to write all the MakeAnd etc etc, by using ASCEND to parse a model containing some logical relations, and then run your routine on those relations directly.
static void test_instantiate_file(void){
from ascend/compiler/test/test_basics.c shows you how to write a show C-language test routine that will load your file and then allow you to access the data structures.