Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
VIGNET Pierre
cadbiom
Commits
3bac9c1a
Commit
3bac9c1a
authored
Dec 03, 2016
by
VIGNET Pierre
Browse files
Proper script before refactoring and suppression of files
parent
09038c6a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
3bac9c1a
...
...
@@ -23,7 +23,7 @@ run_gui:
unit_test
:
@
echo
Unit tests...
./
mac.
sh
$(CMD_PYTHON)
script_
mac.
py
py.test
version
:
...
...
script_mac.py
View file @
3bac9c1a
...
...
@@ -6,7 +6,12 @@ from __future__ import print_function
from
cadbiom.models.clause_constraints.mcl.MCLAnalyser
import
MCLAnalyser
from
cadbiom.models.clause_constraints.mcl.MCLQuery
import
MCLSimpleQuery
import
cadbiom.commons
as
cm
LOGGER
=
cm
.
logger
()
MODEL_FOLDER
=
"/media/DATA/Projets/dyliss_tgf/cadbiom/bio_models/"
RESULT_FOLDER
=
"/media/DATA/Projets/dyliss_tgf/cadbiom/result/"
class
ErrorRep
(
object
):
# Cf class CompilReporter(object):
...
...
@@ -26,118 +31,75 @@ class ErrorRep(object):
def
set_context
(
self
,
cont
):
self
.
context
=
cont
def
logical_or
(
list
):
def
logical_or
(
elements
):
"""
@return logical_formula: str - OR of the input list
"""
if
len
(
list
)
==
0
:
if
len
(
elements
)
==
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
):
elif
len
(
elements
)
==
1
:
return
elements
[
0
]
else
:
return
'('
+
" or "
.
join
(
elements
)
+
')'
def
logical_and
(
elements
):
"""
@return logical_formula: str - AND of the input list
"""
if
len
(
list
)
==
0
:
print
(
"elements:"
,
elements
)
if
len
(
elements
)
==
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
+
')'
elif
len
(
elements
)
==
1
:
return
elements
[
0
]
else
:
return
'('
+
" and "
.
join
(
elements
)
+
')'
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
()
with
open
(
camFile
,
'r'
)
as
file
:
cam_list
=
[
logical_and
(
line
.
rstrip
(
'
\n
'
).
split
(
'
\t
'
))
for
line
in
file
]
if
len
(
cam_list
)
!=
0
:
cam_or
=
logical_or
(
cam_list
)
return
'not('
+
cam_or
+
')'
return
'not('
+
logical_or
(
cam_list
)
+
')'
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'
with
open
(
output_file
,
'a'
)
as
file
:
file
.
write
(
'
\t
'
.
join
(
input_list
)
+
'
\n
'
)
# 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+")"
def
get_last_line
(
input_file
):
with
open
(
input_file
,
"rb"
)
as
f
:
first
=
f
.
readline
()
# Read the first line.
f
.
seek
(
-
2
,
2
)
# Jump to the second last byte.
try
:
while
f
.
read
(
1
)
!=
b
"
\n
"
:
# Until EOL is found...
# Raises an IOError if the file contains only 1 line
f
.
seek
(
-
2
,
1
)
# ...jump back the read byte plus one more.
return
f
.
readline
().
rstrip
(
'
\n
'
)
# Read last line.
except
IOError
:
return
first
.
rstrip
(
'
\n
'
)
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
]
def
main
(
chart_file
,
cam_file
,
cam_step_file
,
cam_complete_file
,
cam_strong_file
,
steps
,
final_prop
,
start_prop
,
inv_prop
):
step
=
int
(
sys
.
argv
[
6
])
LOGGER
.
debug
(
"Params: start: {}, inv: {}, final: {}"
.
format
(
start_prop
,
inv_prop
,
final_prop
))
cam_p
=
None
# forbid previous cam
...
...
@@ -147,15 +109,10 @@ if __name__ == "__main__":
except
:
print
(
'error in camFile2notOr'
)
if
start_p
and
cam_p
:
start_p
+=
' and ('
+
cam_p
+
')'
if
start_p
rop
and
cam_p
:
start_p
rop
+=
' and ('
+
cam_p
+
')'
elif
cam_p
:
start_p
=
cam_p
print
(
'start p : '
,
start_p
)
print
(
'inv p : '
,
inv_p
)
print
(
'final_p : '
,
prop
)
start_prop
=
cam_p
# BUILD MCLA
error_reporter
=
ErrorRep
()
...
...
@@ -191,8 +148,11 @@ if __name__ == "__main__":
# start_prop = None
#
# BUILD QUERY
# final_prop
query
=
MCLSimpleQuery
(
start_p
,
inv_p
,
prop
)
query
=
MCLSimpleQuery
(
start_prop
,
inv_prop
,
final_prop
)
# lsol = mcla.sq_frontier_solutions(query, step, 10)
# print("DEBUG:: " + str(lsol))
# print("DEBUG:: ", len( lsol))
# OPTIMIZE STEP RESEARCH
if
os
.
path
.
isfile
(
cam_step_file
):
...
...
@@ -201,7 +161,7 @@ if __name__ == "__main__":
query
.
set_steps_before_reach
(
min_step
-
1
)
reacheable
=
mcla
.
sq_is_satisfiable
(
query
,
step
)
reacheable
=
mcla
.
sq_is_satisfiable
(
query
,
step
s
)
#important step
print
(
"reacheable:"
,
reacheable
)
min_step
=
mcla
.
unfolder
.
get_current_step
()
print
(
"min_step:"
,
min_step
)
...
...
@@ -209,29 +169,108 @@ if __name__ == "__main__":
query
.
set_steps_before_reach
(
min_step
-
1
)
# FIND NEXT MAC
next_mac_object
=
mcla
.
next_mac
(
query
,
min_step
)
next_mac_object
=
mcla
.
next_mac
(
query
,
min_step
)
#important step
print
(
"next_mac_object:"
,
next_mac_object
)
if
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
)
with
open
(
cam_complete_file
,
'a'
)
as
file
:
next_mac_object
.
save
(
file
)
# SAVE MAC
next_mac
=
next_mac_object
.
activated_frontier
print
(
"save next mac:"
,
next_mac
)
write_list
(
next_mac
,
cam_file
)
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
()
with
open
(
cam_step_file
,
'a'
)
as
file
:
file
.
write
(
str
(
min_step
)
+
'
\n
'
)
return
0
else
:
print
(
"stop"
)
return
1
if
__name__
==
"__main__"
:
import
sys
import
os.path
sys
.
setrecursionlimit
(
10000
)
#print(os.listdir(os.getcwd()))
# EXPERIMENT PARAMS
MODEL_NAME
=
"mini_test_publi"
# MODEL_NAME = "pid_or_clock"
# QUERY PARAMETERS
steps
=
10
# final_prop = "CCR5"
final_prop
=
"P"
start_prop
=
None
inv_prop
=
None
# FILES
CAM_FILE_PREFIX
=
RESULT_FOLDER
+
MODEL_NAME
# chart_file
chart_file
=
MODEL_FOLDER
+
MODEL_NAME
+
".bcx"
# cam_file
cam_file
=
CAM_FILE_PREFIX
+
"_P_cam.txt"
# cam_step_file
cam_step_file
=
CAM_FILE_PREFIX
+
"_P_cam_step.txt"
# cam_complete_file
cam_complete_file
=
CAM_FILE_PREFIX
+
"_P_cam_complete.txt"
# cam_strong_file
cam_strong_file
=
CAM_FILE_PREFIX
+
"_P_cam_strongA.txt"
# Reset files
def
remove_file
(
file
):
try
:
os
.
remove
(
file
)
except
:
pass
remove_file
(
cam_file
)
remove_file
(
cam_step_file
)
remove_file
(
cam_complete_file
)
remove_file
(
cam_strong_file
)
# MAC research
status
=
0
while
status
==
0
:
print
(
"NEW LOOP !"
)
status
=
\
main
(
chart_file
,
# chart_file
cam_file
,
# cam_file
cam_step_file
,
# cam_step_file
cam_complete_file
,
# cam_complete_file
cam_strong_file
,
# cam_strong_file
steps
,
final_prop
,
start_prop
,
inv_prop
)
# QUERY PARAMETERS
# 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+")"
sys
.
exit
(
0
)
else
:
sys
.
exit
(
1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment