smt_lang/solution/
structure.rs1use super::*;
2use crate::problem::*;
3use crate::solve::Smt;
4
5pub struct StrucInstanceValue {
8 id: InstanceId,
9 attributes: Vec<AttributeValue<StructureId>>,
10 methods: Vec<MethodValue<StructureId>>,
11}
12
13impl StrucInstanceValue {
14 pub fn new(smt: &Smt, model: &z3::Model, structure: StructureId, instance: InstanceId) -> Self {
15 let structure = smt.problem().get(structure).unwrap();
16 let mut attributes = Vec::new();
18 for attribute in structure.attributes().iter() {
19 let av = AttributeValue::new(smt, model, instance, attribute.id());
20 attributes.push(av);
21 }
22 let mut methods = Vec::new();
24 for method in structure.methods().iter() {
25 let mv = MethodValue::new(smt, model, instance, method);
26 methods.push(mv);
27 }
28 Self {
30 id: instance,
31 attributes,
32 methods,
33 }
34 }
35}
36
37impl ToLang for StrucInstanceValue {
38 fn to_lang(&self, problem: &Problem) -> String {
39 let instance = problem.get(self.id).unwrap();
40 let mut s = format!(" inst {} {{\n", instance.name());
41 for attribute in self.attributes.iter() {
43 s.push_str(&format!(" {}\n", attribute.to_lang(problem)));
44 }
45 for method in self.methods.iter() {
47 s.push_str(&format!(" {}\n", method.to_lang(problem)));
48 }
49 s.push_str(" }\n");
51 s
52 }
53}
54
55pub struct StructureValue {
58 id: StructureId,
59 instances: Vec<StrucInstanceValue>,
60}
61
62impl StructureValue {
63 pub fn new(smt: &Smt, model: &z3::Model, structure: StructureId) -> Self {
64 let mut instances = Vec::new();
65 for instance in smt
66 .problem()
67 .get(structure)
68 .unwrap()
69 .instances(smt.problem())
70 {
71 instances.push(StrucInstanceValue::new(smt, model, structure, instance));
72 }
73 Self {
74 id: structure,
75 instances,
76 }
77 }
78}
79
80impl ToLang for StructureValue {
81 fn to_lang(&self, problem: &Problem) -> String {
82 let structure = problem.get(self.id).unwrap();
83 let mut s = format!("struct {} {{\n", structure.name());
84 for instance in self.instances.iter() {
85 s.push_str(&instance.to_lang(problem));
86 }
87 s.push_str("}\n");
88 s
89 }
90}