mttMeasureCausalCompletion.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function model = mttMeasureCausalCompletion(model)
  2. number_of_bonds = mttGetFieldLength(model,'bond') ;
  3. for i = 1:number_of_bonds
  4. effort_defined(i) = ~isempty(model.bond(i).effort) ;
  5. flow_defined(i) = ~isempty(model.bond(i).flow) ;
  6. end
  7. partly_defined = effort_defined|flow_defined ;
  8. fully_defined = effort_defined&flow_defined ;
  9. causal_completion.bonds = number_of_bonds ;
  10. causal_completion.flows = sum(flow_defined) ;
  11. causal_completion.efforts = sum(effort_defined) ;
  12. causal_completion.assignments = sum(partly_defined) ;
  13. unicausal_bonds = 0 ;
  14. causal_bond = model.bond(fully_defined) ;
  15. for i = 1:length(causal_bond)
  16. if causal_bond(i).effort==causal_bond(i).flow
  17. unicausal_bonds = unicausal_bonds + 1 ;
  18. end
  19. end
  20. causal_completion.unicausal = unicausal_bonds ;
  21. causal_completion.is_unicausal = causal_completion.assignments==causal_completion.unicausal ;
  22. causal_completion.is_causal = (causal_completion.efforts==causal_completion.bonds) ...
  23. & (causal_completion.flows==causal_completion.bonds) ;
  24. object_names = mttGetFieldNames(model,'obj') ;
  25. number_of_objects = length(object_names) ;
  26. for i = 1:number_of_objects
  27. object_name = object_names{i} ;
  28. object = getfield(model,'obj',object_name) ;
  29. if ~isempty(object.abg)
  30. object = mttMeasureCausalCompletion(object) ;
  31. causal_completion.bonds = causal_completion.bonds + object.causal_completion.bonds ;
  32. causal_completion.flows = causal_completion.flows + object.causal_completion.flows ;
  33. causal_completion.efforts = causal_completion.efforts + object.causal_completion.efforts ;
  34. causal_completion.assignments = causal_completion.assignments + object.causal_completion.assignments ;
  35. causal_completion.unicausal = causal_completion.unicausal + object.causal_completion.unicausal ;
  36. causal_completion.is_unicausal = causal_completion.is_unicausal & object.causal_completion.is_unicausal ;
  37. causal_completion.is_causal = causal_completion.is_causal & object.causal_completion.is_causal ;
  38. end
  39. end
  40. model.causal_completion = causal_completion ;