コード例 #1
0
    def test11(self):
        """Try just saving suffixes, and suffix filter only on read"""
        model = self.setup_model02()

        model.dual[model.g] = 1
        model.ipopt_zL_out[model.x[1]] = 1
        model.ipopt_zL_out[model.x[2]] = 1
        model.ipopt_zU_out[model.x[1]] = 1
        model.ipopt_zU_out[model.x[2]] = 1

        to_json(model, fname=self.fname, wts=StoreSpec.suffix())

        model.dual[model.g] = 10
        model.ipopt_zL_out[model.x[1]] = 10
        model.ipopt_zL_out[model.x[2]] = 10
        model.ipopt_zU_out[model.x[1]] = 10
        model.ipopt_zU_out[model.x[2]] = 10

        wts = StoreSpec.suffix(suffix_filter=("dual", ))
        from_json(model, fname=self.fname, wts=wts)
        assert (abs(model.dual[model.g] - 1) < 1e-5)
        assert (abs(model.ipopt_zL_out[model.x[1]] - 10) < 1e-5)
        assert (abs(model.ipopt_zL_out[model.x[2]] - 10) < 1e-5)
        assert (abs(model.ipopt_zU_out[model.x[1]] - 10) < 1e-5)
        assert (abs(model.ipopt_zU_out[model.x[2]] - 10) < 1e-5)
コード例 #2
0
    def test10(self):
        """Try just saving suffixes, and suffix filter only on write"""
        model = self.setup_model02()

        model.dual[model.g] = 1
        model.ipopt_zL_out[model.x[1]] = 1
        model.ipopt_zL_out[model.x[2]] = 1
        model.ipopt_zU_out[model.x[1]] = 1
        model.ipopt_zU_out[model.x[2]] = 1

        wts = StoreSpec.suffix(suffix_filter=("dual", ))
        to_json(model, fname=self.fname, wts=wts)

        model.dual[model.g] = 10
        model.ipopt_zL_out[model.x[1]] = 10
        model.ipopt_zL_out[model.x[2]] = 10
        model.ipopt_zU_out[model.x[1]] = 10
        model.ipopt_zU_out[model.x[2]] = 10

        from_json(model, fname=self.fname, wts=StoreSpec.suffix())
        assert model.dual[model.g] == 1
        assert model.ipopt_zL_out[model.x[1]] == 10
        assert model.ipopt_zL_out[model.x[2]] == 10
        assert model.ipopt_zU_out[model.x[1]] == 10
        assert model.ipopt_zU_out[model.x[2]] == 10
コード例 #3
0
    def test08(self):
        """Try just saving suffixes"""
        model = self.setup_model02()
        model.x[1].fix(1)

        model.dual[model.g] = 1
        model.ipopt_zL_out[model.x[1]] = 1
        model.ipopt_zL_out[model.x[2]] = 1
        model.ipopt_zU_out[model.x[1]] = 1
        model.ipopt_zU_out[model.x[2]] = 1

        to_json(model, fname=self.fname, wts=StoreSpec.suffix())

        model.dual[model.g] = 10
        model.ipopt_zL_out[model.x[1]] = 10
        model.ipopt_zL_out[model.x[2]] = 10
        model.ipopt_zU_out[model.x[1]] = 10
        model.ipopt_zU_out[model.x[2]] = 10
        model.g.deactivate()
        model.x[1].setlb(-4)
        model.x[1].unfix()
        model.x[2].fix(6)

        from_json(model, fname=self.fname, wts=StoreSpec.suffix())
        assert (abs(value(model.x[1]) - 1) < 1e-5)
        assert (abs(value(model.x[2]) - 6) < 1e-5)
        assert (not model.x[1].fixed)
        assert (model.x[2].fixed)
        assert (not model.g.active)
        assert (abs(model.dual[model.g] - 1) < 1e-5)
        assert (abs(model.ipopt_zL_out[model.x[1]] - 1) < 1e-5)
        assert (abs(model.ipopt_zL_out[model.x[2]] - 1) < 1e-5)
        assert (abs(model.ipopt_zU_out[model.x[1]] - 1) < 1e-5)
        assert (abs(model.ipopt_zU_out[model.x[2]] - 1) < 1e-5)
        assert (abs(model.x[1].lb + 4) < 1e-5)
コード例 #4
0
    def test08(self):
        """Try just saving suffixes"""
        model = self.setup_model02()
        model.x[1].fix(1)

        model.dual[model.g] = 1
        model.ipopt_zL_out[model.x[1]] = 1
        model.ipopt_zL_out[model.x[2]] = 1
        model.ipopt_zU_out[model.x[1]] = 1
        model.ipopt_zU_out[model.x[2]] = 1

        to_json(model, fname=self.fname, wts=StoreSpec.suffix())

        model.dual[model.g] = 10
        model.ipopt_zL_out[model.x[1]] = 10
        model.ipopt_zL_out[model.x[2]] = 10
        model.ipopt_zU_out[model.x[1]] = 10
        model.ipopt_zU_out[model.x[2]] = 10
        model.g.deactivate()
        model.x[1].setlb(-4)
        model.x[1].unfix()
        model.x[2].fix(6)

        from_json(model, fname=self.fname, wts=StoreSpec.suffix())
        assert value(model.x[1]) == 1
        assert value(model.x[2]) == 6
        assert not model.x[1].fixed
        assert model.x[2].fixed
        assert not model.g.active
        assert model.dual[model.g] == 1
        assert model.ipopt_zL_out[model.x[1]] == 1
        assert model.ipopt_zL_out[model.x[2]] == 1
        assert model.ipopt_zU_out[model.x[1]] == 1
        assert model.ipopt_zU_out[model.x[2]] == 1
        assert model.x[1].lb == -4