comparison src/npsol.cc @ 255:98246fedc941

[project @ 1993-12-08 22:55:41 by jwe]
author jwe
date Wed, 08 Dec 1993 22:55:52 +0000
parents a99f28f5e351
children 74d73a4b3fc7
comparison
equal deleted inserted replaced
254:c9894e8d5f04 255:98246fedc941
70 // tree_constant name = tree_constant (npsol_objective->name ()); 70 // tree_constant name = tree_constant (npsol_objective->name ());
71 tree_constant *args = new tree_constant [2]; 71 tree_constant *args = new tree_constant [2];
72 // args[0] = name; 72 // args[0] = name;
73 args[1] = decision_vars; 73 args[1] = decision_vars;
74 74
75 static double retval;
76 retval = 0.0;
77
75 tree_constant objective_value; 78 tree_constant objective_value;
76 if (npsol_objective != NULL_TREE) 79 if (npsol_objective != NULL_TREE)
77 { 80 {
78 tree_constant *tmp = npsol_objective->eval (args, 2, 1, 0); 81 tree_constant *tmp = npsol_objective->eval (args, 2, 1, 0);
82
79 delete [] args; 83 delete [] args;
84
85 if (error_state)
86 {
87 error ("npsol: error evaluating objective function");
88 npsol_objective_error = 1; // XXX FIXME XXX
89 return retval;
90 }
91
80 if (tmp != NULL_TREE_CONST && tmp[0].is_defined ()) 92 if (tmp != NULL_TREE_CONST && tmp[0].is_defined ())
81 { 93 {
82 objective_value = tmp[0]; 94 objective_value = tmp[0];
83 delete [] tmp; 95 delete [] tmp;
84 } 96 }
85 else 97 else
86 { 98 {
87 delete [] tmp; 99 delete [] tmp;
88 error ("npsol: error evaluating objective function"); 100 error ("npsol: error evaluating objective function");
89 jump_to_top_level (); 101 npsol_objective_error = 1; // XXX FIXME XXX
90 } 102 return retval;
91 } 103 }
92 104 }
93 static double retval;
94 retval = 0.0;
95 105
96 switch (objective_value.const_type ()) 106 switch (objective_value.const_type ())
97 { 107 {
98 case tree_constant_rep::matrix_constant: 108 case tree_constant_rep::matrix_constant:
99 { 109 {
100 Matrix m = objective_value.matrix_value (); 110 Matrix m = objective_value.matrix_value ();
101 if (m.rows () == 1 && m.columns () == 1) 111 if (m.rows () == 1 && m.columns () == 1)
102 retval = m.elem (0, 0); 112 retval = m.elem (0, 0);
103 else 113 else
104 gripe_user_returned_invalid ("npsol_objective"); 114 {
115 gripe_user_returned_invalid ("npsol_objective");
116 npsol_objective_error = 1; // XXX FIXME XXX
117 }
105 } 118 }
106 break; 119 break;
107 case tree_constant_rep::scalar_constant: 120 case tree_constant_rep::scalar_constant:
108 retval = objective_value.double_value (); 121 retval = objective_value.double_value ();
109 break; 122 break;
110 default: 123 default:
111 gripe_user_returned_invalid ("npsol_objective"); 124 gripe_user_returned_invalid ("npsol_objective");
125 npsol_objective_error = 1; // XXX FIXME XXX
112 break; 126 break;
113 } 127 }
114 128
115 return retval; 129 return retval;
116 } 130 }
142 args[1] = decision_vars; 156 args[1] = decision_vars;
143 157
144 if (npsol_constraints != NULL_TREE) 158 if (npsol_constraints != NULL_TREE)
145 { 159 {
146 tree_constant *tmp = npsol_constraints->eval (args, 2, 1, 0); 160 tree_constant *tmp = npsol_constraints->eval (args, 2, 1, 0);
161
147 delete [] args; 162 delete [] args;
163
164 if (error_state)
165 {
166 error ("npsol: error evaluating constraints");
167 return retval;
168 }
169
148 if (tmp != NULL_TREE_CONST && tmp[0].is_defined ()) 170 if (tmp != NULL_TREE_CONST && tmp[0].is_defined ())
149 { 171 {
150 retval = tmp[0].to_vector (); 172 retval = tmp[0].to_vector ();
173
151 delete [] tmp; 174 delete [] tmp;
175
176 if (retval.length () <= 0)
177 error ("npsol: error evaluating constraints");
152 } 178 }
153 else 179 else
154 { 180 {
155 delete [] tmp; 181 delete [] tmp;
156 error ("npsol: error evaluating constraints"); 182 error ("npsol: error evaluating constraints");
157 jump_to_top_level ();
158 } 183 }
159 } 184 }
160 185
161 return retval; 186 return retval;
162 } 187 }