package FH is new Formatting_Helpers(pH_Float);
use Answer_Info;
- Guard: Auto_Lock.LC;
pH: pH_Float;
pH_Answered: pH_Float;
begin
- Auto_Lock.Init(Guard, Problem.Mutex'Unchecked_Access);
- Guard.Lock;
-
pH := Calculate_Solution(Problem);
-- Verify answer data
if Answer.Find(ANSWER_PH_KEY) = Answer_Info.No_Element then
end Check_Answer;
function Get_Assignment(Problem: in out Acidobazic_Problem; Assignment: in out Assignment_Info.Map; Resource_Prefix: in String) return RetCode is
- Guard: Auto_Lock.LC;
C: Assignment_Info.Cursor;
Success: Boolean;
pKx: pH_Float;
begin
- Auto_Lock.Init(Guard, Problem.Mutex'Unchecked_Access);
- Guard.Lock;
-
Assignment.Insert(PROBLEM_TYPE_KEY, PROBLEM_TYPE_ACIDOBAZIC, C, Success);
if Success = False then
return E_NOMEM;
end Get_Assignment;
function Get_Parameters(Problem: in out Acidobazic_Problem; Parameters: out Parameters_Info.Map) return RetCode is
- Guard: Auto_Lock.LC;
C: Parameters_Info.Cursor;
Success: Boolean;
begin
- Auto_Lock.Init(Guard, Problem.Mutex'Unchecked_Access);
- Guard.Lock;
-
if Problem.Parameters.No_Both_Simplifications then
Parameters.Insert(PARAMETER_NO_BOTH_SIMPLIFICATIONS_KEY, "True", C, Success);
if Success = False then
package Random_Substance_Type_Gen is new Ada.Numerics.Discrete_Random(Result_Subtype => Substance_Type);
package Random_Dissoc_Type_Gen is new Ada.Numerics.Discrete_Random(Result_Subtype => Dissociation_Constant_Type);
- Guard: Auto_Lock.LC;
DCT_G: Random_Dissoc_Type_Gen.Generator;
ST_G: Random_Substance_Type_Gen.Generator;
cX_Min: pH_Float;
cX_Max: pH_Float;
begin
- Auto_Lock.Init(Guard, Problem.Mutex'Unchecked_Access);
- Guard.Lock;
-- Dissociation constant type (pKa or pKb)
Random_Dissoc_Type_Gen.Reset(Gen => DCT_G);
Problem.DCT := Random_Dissoc_Type_Gen.Random(Gen => DCT_G);
function Set_Parameters(Problem: in out Acidobazic_Problem; Parameters: in Parameters_Info.Map) return RetCode is
use Parameters_Info;
-
- Guard: Auto_Lock.LC;
begin
- Auto_Lock.Init(Guard, Problem.Mutex'Unchecked_Access);
- Guard.Lock;
-
if Parameters.Find(PARAMETER_NO_BOTH_SIMPLIFICATIONS_KEY) = Parameters_Info.No_Element then
Problem.Parameters.No_Both_Simplifications := False;
else
use Answer_Info;
use FH;
- Guard: Auto_Lock.LC;
AF: SS_Float;
Int_Part_Got: Integer;
Int_Part_Calcd: Integer;
Exp_Part_Got: Integer;
Exp_Part_Calcd: Integer;
begin
- Auto_Lock.Init(Guard, Problem.Mutex'Unchecked_Access);
- Guard.Lock;
-- Check that there is a valid answer in the map
if Answer.Find(ANSWER_NUM_KEY) = Answer_Info.No_Element then
return No_Answer;
function Get_Assignment(Problem: in out Solubility_Problem; Assignment: in out Assignment_Info.Map; Resource_Prefix: in String) return RetCode is
package FH is new Formatting_Helpers(SS_Float);
use FH;
-
- Guard: Auto_Lock.LC;
begin
- Auto_Lock.Init(Guard, Problem.Mutex'Unchecked_Access);
- Guard.Lock;
Assignment.Insert(PROBLEM_TYPE_KEY, PROBLEM_TYPE_SOLUBILITY);
Assignment.Insert(PROBLEM_SUBTYPE_KEY, Problem_Subtype'Image(Problem.Parameters.P_Subtype));
end Get_Assignment;
function Get_Parameters(Problem: in out Solubility_Problem; Parameters: out Parameters_Info.Map) return RetCode is
- Guard: Auto_Lock.LC;
C: Parameters_Info.Cursor;
Success: Boolean;
begin
- Auto_Lock.Init(Guard, Problem.Mutex'Unchecked_Access);
- Guard.Lock;
-
if Problem.Parameters.Ionic_Strength then
Parameters.Insert(PARAMETER_IONIC_STRENGTH_KEY, "True", C, Success);
if Success = False then
Stochio_RGen: Random_Stochio_Count.Generator;
Float_RGen: Generator;
- Guard: Auto_Lock.LC;
M: Stochiometric_Count; -- Number of cations
N: Stochiometric_Count; -- Number of anions
Answer_Num: SS_Float; -- Answer to this problem
Prob_Data: Solubility_Problem_Data; -- Assignment data
begin
- Auto_Lock.Init(Guard, Problem.Mutex'Unchecked_Access);
- Guard.Lock;
Reset(Gen => Float_RGen);
-- Generate stochiometry of the molecul
function Set_Parameters(Problem: in out Solubility_Problem; Parameters: in Parameters_Info.Map) return RetCode is
use Parameters_Info;
-
- Guard: Auto_Lock.LC;
begin
- Auto_Lock.Init(Guard, Problem.Mutex'Unchecked_Access);
- Guard.Lock;
-- Change ionic strength settings
if Parameters.Find(PARAMETER_IONIC_STRENGTH_KEY) /= Parameters_Info.No_Element then
Problem.Parameters.Ionic_Strength := True;
package body Problem_Generator is
- package body Auto_Lock is
- procedure Init(This: in out LC; Mutex: Simple_Mutex_All_Access; Auto_Unlock: in Boolean := True) is
- begin
- This.Auto_Unlock := Auto_Unlock;
- This.Mutex := Mutex;
- end;
-
- procedure Lock(This: in out LC) is
- begin
- This.Mutex.Lock;
- end Lock;
-
- procedure Unlock(This: in out LC) is
- begin
- This.Mutex.Unlock;
- end Unlock;
-
- procedure Finalize(This: in out LC) is
- begin
- if This.Auto_Unlock then
- This.Unlock;
- end if;
- end Finalize;
- end Auto_Lock;
-
function Get_Problem(P_Type: in Problem_Type) return access Chem_Problem'Class is
begin
case P_Type is
function Get_Problem(P_Type: in Problem_Type) return access Chem_Problem'Class;
private
- type Chem_Problem is abstract limited new Ada.Finalization.Limited_Controlled with
- record
- Mutex: aliased Simple_Mutex;
- end record;
-
- package Auto_Lock is
- type LC is limited new Ada.Finalization.Limited_Controlled with private;
- procedure Init(This: in out LC; Mutex: Simple_Mutex_All_Access; Auto_Unlock: in Boolean := True);
- procedure Lock(This: in out LC);
- procedure Unlock(This: in out LC);
- private
- type LC is limited new Ada.Finalization.Limited_Controlled with
- record
- Auto_Unlock: Boolean;
- Mutex: Simple_Mutex_All_Access;
- end record;
- overriding procedure Finalize(This: in out LC);
- end Auto_Lock;
+
+ type Chem_Problem is abstract limited new Ada.Finalization.Limited_Controlled with null record;
package Acidobazic_Suite is
use Problem_Generator_Syswides.Acidobazic_Suite;