Esempio n. 1
0
    def testGlp(self):
        """Test reading/writing GNU LP format."""
        self.lp.write(glp=self.f.name)
        lp = LPX(glp=self.f.name)
        self.assertEqual(len(lp.rows), 1)
        self.assertEqual(len(lp.cols), 2)
        self.assertEqual(lp.cols[0].name, 'x')
        self.assertEqual(lp.cols[1].name, 'y')

        # try to read a non-existing file
        with self.assertRaises(RuntimeError) as cm:
            lp = LPX(glp='not a real file')
        self.assertIn('GLPK LP/MIP reader failed', str(cm.exception))

        # try to write to a non-existing path
        with self.assertRaises(RuntimeError) as cm:
            lp.write(glp='not/a/real/file')
        self.assertIn("writer for 'glp' failed to write to 'not/a/real/file'",
                      str(cm.exception))
Esempio n. 2
0
    def testFreeMps(self):
        """Test reading/writing free MPS format."""
        self.lp.write(freemps=self.f.name)
        lp = LPX(freemps=self.f.name)
        self.assertEqual(len(lp.rows), 1)
        self.assertEqual(len(lp.cols), 2)
        self.assertEqual(lp.cols[0].name, 'x')
        self.assertEqual(lp.cols[1].name, 'y')

        # try to read a non-existing file
        with self.assertRaises(RuntimeError) as cm:
            lp = LPX(freemps='not a real file')
        self.assertIn('Free MPS reader failed', str(cm.exception))

        # try to write to a non-existing path
        with self.assertRaises(RuntimeError) as cm:
            lp.write(freemps='not/a/real/file')
        self.assertIn(
            "writer for 'freemps' failed to write to 'not/a/real/file'",
            str(cm.exception))
Esempio n. 3
0
    def testCpxLp(self):
        """Test reading/writing CPLEX LP format."""
        self.lp.write(cpxlp=self.f.name)
        lp = LPX(cpxlp=self.f.name)
        self.assertEqual(len(lp.rows), 1)
        self.assertEqual(len(lp.cols), 2)
        self.assertEqual(lp.cols[0].name, 'x')
        self.assertEqual(lp.cols[1].name, 'y')

        # try to read a non-existing file
        with self.assertRaises(RuntimeError) as cm:
            lp = LPX(cpxlp='not a real file')
        self.assertIn('CPLEX LP reader failed', str(cm.exception))

        # try to write to a non-existing path
        with self.assertRaises(RuntimeError) as cm:
            lp.write(cpxlp='not/a/real/file')
        self.assertIn(
            "writer for 'cpxlp' failed to write to 'not/a/real/file'",
            str(cm.exception)
        )
Esempio n. 4
0
    def testFreeMps(self):
        """Test reading/writing free MPS format."""
        self.lp.write(freemps=self.f.name)
        lp = LPX(freemps=self.f.name)
        self.assertEqual(len(lp.rows), 1)
        self.assertEqual(len(lp.cols), 2)
        self.assertEqual(lp.cols[0].name, 'x')
        self.assertEqual(lp.cols[1].name, 'y')

        # try to read a non-existing file
        with self.assertRaises(RuntimeError) as cm:
            lp = LPX(freemps='not a real file')
        self.assertIn('Free MPS reader failed', str(cm.exception))

        # try to write to a non-existing path
        with self.assertRaises(RuntimeError) as cm:
            lp.write(freemps='not/a/real/file')
        self.assertIn(
            "writer for 'freemps' failed to write to 'not/a/real/file'",
            str(cm.exception)
        )