Commit 09038c6a authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

First commit - Annoted original scripts

parent d4d32ac0
#! /bin/bash
#$ -S /bin/bash
#$ -m bea
# . /local/env/envpython-2.7.sh
# export PYTHONPATH=~/cadbiom/:~/cadbiom/solver/
# model info
model_folder="bio_models/"
model_name="mini_test_publi"
model_ext=".bcx"
model="$model_folder$model_name$model_ext"
# results info
result_folder="result/"
p_ext="_P"
result_ext="_cam.txt"
step_ext="_cam_step.txt"
complete_ext="_cam_complete.txt"
# Delete previous results
camF="$result_folder$model_name$p_ext$result_ext"
if [ -f $camF ]
then
rm $camF
fi
stepF="$result_folder$model_name$p_ext$step_ext"
if [ -f $stepF ]
then
rm $stepF
fi
completeF="$result_folder$model_name$p_ext$complete_ext"
if [ -f $completeF ]
then
rm $completeF
fi
# Parameters
inv_p="n"
start_p="n"
p="P"
step="10"
# MAC research
tt=0
while [ $tt -eq 0 ];
do
python "script_mac.py" $model $camF "$inv_p" "$start_p" "$p" $step
tt=$?
echo $tt
echo ""
done
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
from cadbiom.models.clause_constraints.mcl.MCLAnalyser import MCLAnalyser
from cadbiom.models.clause_constraints.mcl.MCLQuery import MCLSimpleQuery
class ErrorRep(object):
# Cf class CompilReporter(object):
# gt_gui/utils/reporter.py
def __init__(self):
self.context = ""
self.error = False
pass
def display(self, mess):
self.error = True
print('\n>> '+self.context+" "+mess)
def display_info(self, mess):
print('\n-- '+mess)
def set_context(self, cont):
self.context = cont
def logical_or(list):
"""
@return logical_formula: str - OR of the input list
"""
if len(list)==0 :
return
elif len(list)==1 :
return list[0]
else :
logical_formula = ''
for elemnt in list :
logical_formula +=elemnt+' or '
logical_formula = logical_formula[:-4]
# print logical_formula
return '('+logical_formula+')'
def logical_and(list):
"""
@return logical_formula: str - AND of the input list
"""
if len(list)==0 :
return
elif len(list)==1 :
return list[0]
else :
logical_formula = ''
for elemnt in list :
logical_formula +=elemnt+' and '
logical_formula = logical_formula[:-5]
return '('+logical_formula+')'
def camFile2notOr(camFile):
"""
translate a cam file into a logical formula to forbid previous cam
"""
cam_list = []
f=open(camFile,'r')
for line in f :
place_list =[]
new_line = line.split('\t')
place_and = logical_and(new_line[:-1])
cam_list.append(place_and)
f.close()
if len(cam_list) != 0:
cam_or = logical_or(cam_list)
return 'not('+cam_or+')'
else :
return ''
def write_list(input_list, output_file) :
"""
write input_list in output_file, tabular form
"""
f=open(output_file,'a')
for elemt in input_list :
f.write(elemt+'\t')
f.write('\n')
f.close()
def get_last_line(input_file):
list_of_line = []
f=open(input_file,'r')
for line in f :
line = line.split()
list_of_line.append(line[0])#remove \n
f.close()
return list_of_line[-1]
if __name__ == "__main__":
import sys
import os.path
sys.setrecursionlimit(10000)
sys.path.append('~/cadbiom/solver') # SOLVER FOLDER
#AFFECT ARGUMENTS
print("APPEL !")
# FILES
chart_file = sys.argv[1]
cam_file = sys.argv[2]
cam_step_file = cam_file[:-4] + '_step.txt'
cam_complete_file = cam_file[:-4] + '_complete.txt'
cam_strong_file = cam_file[:-4] + '_strongA.txt'
# QUERY PARAMETERS
if sys.argv[3] == 'n':
inv_p = None
else :
inv_p = sys.argv[3]
# if self.possible:
# if len(inv_prop) == 0:
# inv_prop = None
# else :
# inv_prop = "not ("+inv_prop+")"
# else:
# if len(inv_prop) != 0:
# sert pas:
# final_prop = "not ("+final_prop+" and "+inv_prop+")"
if sys.argv[4] == 'n':
start_p = None
else :
start_p = sys.argv[4]
if sys.argv[5] == 'n':
prop = None
else :
prop = sys.argv[5]
step = int(sys.argv[6])
cam_p = None
# forbid previous cam
try :
cam_p = camFile2notOr(cam_file)
print("cam file:", cam_p)
except :
print('error in camFile2notOr')
if start_p and cam_p :
start_p += ' and ('+cam_p+')'
elif cam_p :
start_p = cam_p
print('start p : ', start_p)
print('inv p : ', inv_p)
print('final_p : ', prop)
# BUILD MCLA
error_reporter = ErrorRep()
mcla = MCLAnalyser(error_reporter)
# build_from_chart_model
# Build an MCLAnalyser from a chartmodel object
# @param model: object - ChartModel
# = représentation interne...
# build_from_chart_file
# Build an MCLAnalyser from a .bcx file
# @param file_name: str - path of the .bcx file
# build_from_pid_file
# Build an MCLAnalyser from a .xml file of PID database
# @param file_name: str - path of .xml file
# build_from_cadlang
# Build an MCLAnalyser from a .cal file of PID database
# @param file_name: str - path of .cal file
mcla.build_from_chart_file(chart_file)
if error_reporter.error:
#cancel_warn(error_reporter.memory)
#error_reporter.reset()
#return
print("ERROR:: " + error_reporter.error)
raise
#
# if len(inv_prop) == 0:
# inv_prop = None
# else :
# inv_prop = "not ("+inv_prop+")"
#
# if len(start_prop) == 0:
# start_prop = None
#
# BUILD QUERY
# final_prop
query = MCLSimpleQuery(start_p, inv_p, prop)
# OPTIMIZE STEP RESEARCH
if os.path.isfile(cam_step_file):
min_step = int(get_last_line(cam_step_file))
print("min_step opti:", min_step)
query.set_steps_before_reach(min_step-1)
reacheable = mcla.sq_is_satisfiable(query, step)
print("reacheable:", reacheable)
min_step = mcla.unfolder.get_current_step()
print("min_step:", min_step)
# Set max step authorized
query.set_steps_before_reach(min_step-1)
# FIND NEXT MAC
next_mac_object = mcla.next_mac(query, min_step)
print("next_mac_object:", next_mac_object)
if next_mac_object :
# SAVE MAC AND TIMING
cam_complete_file = open(cam_complete_file,'a')
next_mac_object.save(cam_complete_file)
# SAVE MAC
next_mac = next_mac_object.activated_frontier
print("save next mac:", next_mac)
write_list(next_mac,cam_file)
# SAVE STEP
min_step = mcla.unfolder.get_current_step()
print("save min step:", min_step)
step_file = open(cam_step_file,'a')
step_file.write(str(min_step)+'\n')
step_file.close()
sys.exit(0)
else :
sys.exit(1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment