Author: luc
Date: Tue Jun 2 09:06:26 2009
New Revision: 780976
URL: http://svn.apache.org/viewvc?rev=780976&view=rev
Log:
fixed serialization problems
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/LinearConstraint.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/LinearObjectiveFunction.java
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/LinearConstraint.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/LinearConstraint.java?rev=780976&r1=780975&r2=780976&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/LinearConstraint.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/LinearConstraint.java
Tue Jun 2 09:06:26 2009
@@ -17,8 +17,12 @@
package org.apache.commons.math.optimization.linear;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
+import org.apache.commons.math.linear.MatrixUtils;
import org.apache.commons.math.linear.RealVector;
import org.apache.commons.math.linear.RealVectorImpl;
@@ -50,7 +54,7 @@
private static final long serialVersionUID = -764632794033034092L;
/** Coefficients of the constraint (left hand side). */
- private final RealVector coefficients;
+ private final transient RealVector coefficients;
/** Relationship between left and right hand sides (=, <=, >=). */
private final Relationship relationship;
@@ -180,4 +184,59 @@
return value;
}
+ /** {...@inheritdoc} */
+ @Override
+ public boolean equals(Object other) {
+
+ if (this == other) {
+ return true;
+ }
+
+ if (other == null) {
+ return false;
+ }
+
+ try {
+
+ LinearConstraint rhs = (LinearConstraint) other;
+ return (relationship == rhs.relationship) &&
+ (value == rhs.value) &&
+ coefficients.equals(rhs.coefficients);
+
+ } catch (ClassCastException ex) {
+ // ignore exception
+ return false;
+ }
+
+ }
+
+ /** {...@inheritdoc} */
+ @Override
+ public int hashCode() {
+ return relationship.hashCode() ^
+ Double.valueOf(value).hashCode() ^
+ coefficients.hashCode();
+ }
+
+ /** Serialize the instance.
+ * @param oos stream where object should be written
+ * @throws IOException if object cannot be written to stream
+ */
+ private void writeObject(ObjectOutputStream oos)
+ throws IOException {
+ oos.defaultWriteObject();
+ MatrixUtils.serializeRealVector(coefficients, oos);
+ }
+
+ /** Deserialize the instance.
+ * @param ois stream from which the object should be read
+ * @throws ClassNotFoundException if a class in the stream cannot be found
+ * @throws IOException if object cannot be read from the stream
+ */
+ private void readObject(ObjectInputStream ois)
+ throws ClassNotFoundException, IOException {
+ ois.defaultReadObject();
+ MatrixUtils.deserializeRealVector(this, "coefficients", ois);
+ }
+
}
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/LinearObjectiveFunction.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/LinearObjectiveFunction.java?rev=780976&r1=780975&r2=780976&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/LinearObjectiveFunction.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/LinearObjectiveFunction.java
Tue Jun 2 09:06:26 2009
@@ -17,8 +17,12 @@
package org.apache.commons.math.optimization.linear;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
+import org.apache.commons.math.linear.MatrixUtils;
import org.apache.commons.math.linear.RealVector;
import org.apache.commons.math.linear.RealVectorImpl;
@@ -41,7 +45,7 @@
private static final long serialVersionUID = -4531815507568396090L;
/** Coefficients of the constraint (c<sub>i</sub>). */
- private final RealVector coefficients;
+ private final transient RealVector coefficients;
/** Constant term of the linear equation. */
private final double constantTerm;
@@ -97,4 +101,55 @@
return coefficients.dotProduct(point) + constantTerm;
}
+ /** {...@inheritdoc} */
+ @Override
+ public boolean equals(Object other) {
+
+ if (this == other) {
+ return true;
+ }
+
+ if (other == null) {
+ return false;
+ }
+
+ try {
+
+ LinearObjectiveFunction rhs = (LinearObjectiveFunction) other;
+ return (constantTerm == rhs.constantTerm) &&
coefficients.equals(rhs.coefficients);
+
+ } catch (ClassCastException ex) {
+ // ignore exception
+ return false;
+ }
+
+ }
+
+ /** {...@inheritdoc} */
+ @Override
+ public int hashCode() {
+ return Double.valueOf(constantTerm).hashCode() ^
coefficients.hashCode();
+ }
+
+ /** Serialize the instance.
+ * @param oos stream where object should be written
+ * @throws IOException if object cannot be written to stream
+ */
+ private void writeObject(ObjectOutputStream oos)
+ throws IOException {
+ oos.defaultWriteObject();
+ MatrixUtils.serializeRealVector(coefficients, oos);
+ }
+
+ /** Deserialize the instance.
+ * @param ois stream from which the object should be read
+ * @throws ClassNotFoundException if a class in the stream cannot be found
+ * @throws IOException if object cannot be read from the stream
+ */
+ private void readObject(ObjectInputStream ois)
+ throws ClassNotFoundException, IOException {
+ ois.defaultReadObject();
+ MatrixUtils.deserializeRealVector(this, "coefficients", ois);
+ }
+
}
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java?rev=780976&r1=780975&r2=780976&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java
Tue Jun 2 09:06:26 2009
@@ -17,11 +17,15 @@
package org.apache.commons.math.optimization.linear;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import org.apache.commons.math.linear.MatrixUtils;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.RealMatrixImpl;
import org.apache.commons.math.linear.RealVector;
@@ -69,7 +73,7 @@
private final boolean restrictToNonNegative;
/** Simple tableau. */
- protected RealMatrix tableau;
+ protected transient RealMatrix tableau;
/** Number of decision variables. */
protected final int numDecisionVariables;
@@ -488,4 +492,68 @@
return tableau.getData();
}
+ /** {...@inheritdoc} */
+ @Override
+ public boolean equals(Object other) {
+
+ if (this == other) {
+ return true;
+ }
+
+ if (other == null) {
+ return false;
+ }
+
+ try {
+
+ SimplexTableau rhs = (SimplexTableau) other;
+ return (restrictToNonNegative == rhs.restrictToNonNegative) &&
+ (numDecisionVariables == rhs.numDecisionVariables) &&
+ (numSlackVariables == rhs.numSlackVariables) &&
+ (numArtificialVariables == rhs.numArtificialVariables) &&
+ (epsilon == rhs.epsilon) &&
+ f.equals(rhs.f) &&
+ constraints.equals(rhs.constraints) &&
+ tableau.equals(rhs.tableau);
+
+ } catch (ClassCastException ex) {
+ // ignore exception
+ return false;
+ }
+
+ }
+
+ /** {...@inheritdoc} */
+ @Override
+ public int hashCode() {
+ return Boolean.valueOf(restrictToNonNegative).hashCode() ^
+ numDecisionVariables ^
+ numSlackVariables ^
+ numArtificialVariables ^
+ Double.valueOf(epsilon).hashCode() ^
+ f.hashCode() ^
+ constraints.hashCode() ^
+ tableau.hashCode();
+ }
+
+ /** Serialize the instance.
+ * @param oos stream where object should be written
+ * @throws IOException if object cannot be written to stream
+ */
+ private void writeObject(ObjectOutputStream oos)
+ throws IOException {
+ oos.defaultWriteObject();
+ MatrixUtils.serializeRealMatrix(tableau, oos);
+ }
+
+ /** Deserialize the instance.
+ * @param ois stream from which the object should be read
+ * @throws ClassNotFoundException if a class in the stream cannot be found
+ * @throws IOException if object cannot be read from the stream
+ */
+ private void readObject(ObjectInputStream ois)
+ throws ClassNotFoundException, IOException {
+ ois.defaultReadObject();
+ MatrixUtils.deserializeRealMatrix(this, "tableau", ois);
+ }
}